如何在Bot Framework Web Chat中使用Azure语音服务

时间:2018-11-09 05:14:44

标签: botframework

我正在使用Bot Framework网络聊天,并且已经正确设置了前端供用户与我的机器人聊天。我正在尝试为此启用语音功能,我尝试按照此处的教程进行操作:https://docs.microsoft.com/en-us/azure/bot-service/bot-service-channel-connect-webchat-speech?view=azure-bot-service-3.0

我遇到的问题是我尝试使用Azure语音服务,正确设置了服务,并且设置了密钥。但是我不确定从哪里获得CognitiveServices?本教程未指定从何处获得它。

这是我的代码:

<div  id="bot"/>
<script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>
<script>

    const speechOptionsRemote = {
        speechRecognizer: new CognitiveServices.SpeechRecognizer({ subscriptionKey: '...' }),
        speechSynthesizer: new CognitiveServices.SpeechSynthesizer({
            gender: CognitiveServices.SynthesisGender.Female,
            subscriptionKey: '...',
            voiceName: 'Microsoft Server Speech Text to Speech Voice (en-US, JessaRUS)'
        })
    };

    BotChat.App({
        directLine: { secret: '...' },
        user: { id: 'WebChat' },
        bot: { id: '...' },
        resize: 'detect',
        speechOptions: speechOptionsRemote,
        showUploadButton: false
    }, document.getElementById("bot"));
    var header = document.getElementsByClassName("wc-header");
    header[0].innerHTML = "<span ><p align='center' >My Bot</p></span>"
</script>

当我导航到页面时,它抱怨找不到CogntiveService。我在哪里得到的?

1 个答案:

答案 0 :(得分:1)

您的代码示例使用的是Webchat v3,现已弃用,请参见here。 GitHub存储库上有一个v4的BotFramework-WebChat,更新已在几天前完成。

因此,当您在代码中下载train_data时,正是v4:解释了为什么找不到cdn.botframework.com/botframework-webchat/latest/botchat.js的原因:它已被重构。

要在v4中使用认知服务语音,请查看专用示例:https://github.com/Microsoft/BotFramework-WebChat/tree/master/samples/speech-cognitive-services-bing-speech