如何将实时语音添加到 Microsoft Bot 框架的文本数据(正是 google 语音的作用)

How to add live speech to text data for microsoft bot framework(exactly what google speech does)

我是 Microsoft Bot 框架的新手。我已经构建了一个简单的聊天机器人,当我发布它并将其部署到 webapp 频道时,它看起来像这样

用户将 select 或键入文本,机器人将响应。现在我需要的是,我需要在发送选项附近添加一个麦克风,这样如果用户点击麦克风并开始说话,那么它应该由机器人自动输入(google 语音的确切方式)

我有 bing 语音转文本 api 参考键,但我不知道如何添加和激活其中的麦克风功能。

有知道的请帮我解决一下

您可以利用 Embeddable web chat control for the Microsoft Bot Framework plugin in your web application. You can refer to https://github.com/Microsoft/BotFramework-WebChat/blob/master/samples/speech/index.html 作为语音样本。

一般来说,为了快速测试代码中的一些要点:

  1. 在您的网页中包含样式和脚本文件:

<link href='https://cdn.botframework.com/botframework-webchat/latest/botchat.css' rel="stylesheet"/> ... <script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script> <script src="https://cdn.botframework.com/botframework-webchat/latest/CognitiveServices.js"></script>

  1. 初始化语音选项:

    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)'
      })
    };
    
  2. 在脚本中初始化 BotChat:

    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,
      // locale: 'es-es', // override locale to Spanish
      directLine: {
        domain: params['domain'],
        secret: params['s'],
        token: params['t'],
        webSocket: params['webSocket'] && params['webSocket'] === 'true' // defaults to true
      }
    }, document.getElementById('BotChatGoesHere'));