将机器人与 Azure 语音服务集成问题


尝试

通过浏览器在机器人上使用 Azure 语音服务时出现语音服务异常

使用 IE、Chrome 和 Firefox 在我的机器人上触发语音识别时出现以下异常:SCRIPT12008:SCRIPT12008:WebSocket 错误:HTTP 响应不正确。状态代码 401,未授权机器人适用于键入的消息,但在用户单击麦克风图标时失败。我正在使用直线与机器人通信。你能提供建议吗?提前感谢

<!DOCTYPE html>
<html>
  <head>
      <meta charset="utf-8">
    <link href="https://cdn.botframework.com/botframework-webchat/latest/botchat.css" rel="stylesheet" />
    <link href="chat-assets/css/botchat-override.css" rel="stylesheet" />
      <style> 
          html,body{height: 100%}
      </style>
  </head>
  <body style="background-color: #fff; background-image: url('aila-msbot.jpg'); background-repeat: no-repeat; background-position: center center; background-size: 100%; ">
    <div id="bot-holder">   
        <div id="bot-container">
            <div class="bot-header">
                <div class="icon-holder">
                    <div class="icon"></div>
                </div>
                <div class="bot-title">Aila</div>
                <a href="javascript:closeChat()">X</a>
            </div>
            <div id="bot"></div>
        </div>
        <a id="bot-minimize" class="hide" href="javascript:startChat();">
            <div class="comment"></div>
        </a>
    </div>

    <script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>
    <script src="https://cdn.botframework.com/botframework-webchat/latest/CognitiveServices.js"></script>
        <script>
            var user = {
                id: 'User',
                name: 'You'
            };
            var botConnection = new BotChat.DirectLine({
                token: 'XXXXXXXXXXXX',
                user: user
            });
var speechOptions = {
    speechRecognizer: new CognitiveServices.SpeechRecognizer( { subscriptionKey: 'XXXXXXXXXXXX'} ),
    speechSynthesizer: new CognitiveServices.SpeechSynthesizer(
        {
            subscriptionKey: 'XXXXXXXXXXXX',
            gender: CognitiveServices.SynthesisGender.Female,
            voiceName: 'Microsoft Server Speech Text to Speech Voice (en-US, JessaRUS)'
        })
};
            BotChat.App({
                user: user,
                botConnection: botConnection,
    speechOptions: speechOptions,
                bot: { id: 'XXXXXXXXXXXX', name: 'Bella' },
                resize: 'detect'
            }, document.getElementById("bot"));
            botConnection
                .postActivity({
                    from: user,
                    name: 'requestWelcomeDialog',
                    type: 'event',
                    value: ''
                })
                .subscribe(function (id) {
                    console.log('"trigger requestWelcomeDialog" sent');
                });
      function closeChat(){
        var chatWin = document.getElementById('bot-container');
        var closeIcon = document.getElementById('bot-minimize');
        chatWin.classList.add('hide');
        closeIcon.classList.remove('hide');
      }
      function startChat(){
        var chatWin = document.getElementById('bot-container');
        var closeIcon = document.getElementById('bot-minimize');
        chatWin.classList.remove('hide');
        closeIcon.classList.add('hide');
      }
      onload = function(){
        //closeChat();
      }
    </script>
  </body>
</html>

必应搜索已过时。建议使用 Azure 搜索,但 botchat.js 不支持此方法。因此,迁移到网络聊天.cs是必要的。更多信息请访问 https://www.npmjs.com/package/botframework-webchat

最新更新