首页 > 解决方案 > 如何在网络聊天中使用新的 Azure 语音服务而不是 Bing 语音

问题描述

我有一个网络聊天机器人工作正常(我可以使用语音并返回语音)使用以下链接的必应语音:

使用选项 3:

https://github.com/Microsoft/BotFramework-Samples/blob/master/docs-samples/web-chat-speech/index.html

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

但是,我正在尝试从 Bing Speech API 切换到 Speech Services AP,因为 Bing Speech 即将退役。

有谁知道如何为我的网络聊天机器人执行此操作?

标签: node.jsazurebotframeworkweb-chatbing-speech

解决方案


webchat v3 不支持 azure 的 Cognitive Speech Service。但在 webchat v4 中,您可以通过以下代码进行集成

const config = {
                    method: "POST",
                    headers: {
                        Authorization:
                            "Bearer  xxwebchatsecretkeyxx"
                    }
                };
     const res = await fetch(
                    "https://directline.botframework.com/v3/directline/tokens/generate",
                    config
                );

                const subscriptionKey = "speech service subscription key";

                const { token } = await res.json();

                let directLine = window.WebChat.createDirectLine({ token });
    window.WebChat.renderWebChat(
                        {
                            directLine,
                            webSpeechPonyfillFactory: await window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory(
                                {
                                    region: "westus",
                                    subscriptionKey
                                }
                            ),
                            userID: model.id,
                            styleSet,
                            store
                        },
                   document.getElementById("webchat")
                );

推荐阅读