我使用 Microsoft QnA Maker 服务和 Azure 上托管的 Azure Web App 机器人创建了一个网络聊天机器人。我在 Azure 上为我的机器人启用了 Web 聊天和 Direct Line 频道。它工作正常。现在我正在尝试集成 Bing Speech API 以进行语音识别。下面是代码-
图书馆:
<script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>
<script src="https://cdn.botframework.com/botframework-webchat/latest/CognitiveServices.js"></script>
在 JavaScript 中创建 Web 应用程序机器人:
const speechOptions = {
speechRecognizer: new CognitiveServices.SpeechRecognizer({ subscriptionKey: <key> }),
speechSynthesizer: new CognitiveServices.SpeechSynthesizer({
gender: CognitiveServices.SynthesisGender.Female,
subscriptionKey: <key>,
voiceName: 'Microsoft Server Speech Text to Speech Voice (en-US, JessaRUS)'
})
};
BotChat.App({
bot: bot,
locale: params['locale'],
resize: 'detect',
// sendTyping: true, // defaults to false. set to true to send 'typing' activities to bot (and other users) when user is typing
speechOptions: speechOptions,
user: user,
directLine: {
domain: params['domain'],
secret: params['s'],
token: params['t'],
webSocket: params['webSocket'] && params['webSocket'] === 'true' // defaults to true
}
}, document.getElementById('chatBot'));
当我在 Chrome 或 Edge 上运行此程序时,我可以单击麦克风并说话,然后我会得到响应(基于 QnA 制造商中的 Key-Answer 映射)以文本和语音的形式返回。问题是,如果答案太长(如 600 个字符),我只能得到文本作为响应,但没有声音。
对此有什么帮助吗?如果我可以提供更多详细信息,请告诉我。