【问题标题】:Microsoft Bot Framework speech recognition webchat integrationMicrosoft Bot Framework 语音识别网络聊天集成
【发布时间】:2020-01-19 23:51:34
【问题描述】:

我在将语音识别集成到网络聊天时遇到问题。这是我使用的代码。就像这里的代码一样:https://github.com/microsoft/BotFramework-WebChat/blob/master/SPEECH.md#integrating-web-chat-into-your-page

但我总是收到错误:Uncaught SyntaxError: Unexpected identifier at line...

错误行是:webSpeechPonyfillFactory: await createSpeechRecognitionOnlyPonyfillFactory({

没有语音识别,一切正常。你有什么想法吗?

const { createCognitiveServicesSpeechServicesPonyfillFactory, createDirectLine, renderWebChat } = window.WebChat;

const styleOptions = {
		botAvatarInitials: 'Bot',
		userAvatarInitials: 'You'
		};


         renderWebChat(
            {
               directLine: createDirectLine({
                  secret: 'FFFFFFFFFFFFFFFF'
               }),
			   
	     language: 'de-DE',
	     webSpeechPonyfillFactory: await createSpeechRecognitionOnlyPonyfillFactory({
	     region: 'westeurope',
	     subscriptionKey: 'FFFFFFFFFFFFFFFFFFFFFF'
	     }),
			   	      
	      styleOptions
  	     
            },
            document.getElementById('webchat')
	);
         
document.querySelector('#webchat > *').focus();

【问题讨论】:

    标签: javascript botframework speech-recognition web-chat


    【解决方案1】:

    试试这个:

     <!DOCTYPE html>
      <html lang="en-US">
        <head>
          <title>Web Chat: Cognitive Services Speech Services using JavaScript</title>
          <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
          <style>
            html, body { height: 100% }
            body { margin: 0 }
    
            #webchat {
              height: 100%;
              width: 100%;
            }
          </style>
        </head>
        <body>
          <div id="webchat" role="main"></div>
          <script>
            (async function () {
                const styleOptions = {
                    botAvatarInitials: 'Bot',
                    userAvatarInitials: 'You'
                    };
    
                window.WebChat.renderWebChat({
                directLine: createDirectLine({
                    secret: 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
                  }),
                  language: 'de-DE',
                  webSpeechPonyfillFactory: await createCognitiveServicesSpeechServicesPonyfillFactory({
                    region: 'westeurope',
                    subscriptionKey: 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
                  }),
                  styleOptions
                }, document.getElementById('webchat'));
                document.querySelector('#webchat > *').focus();
            })().catch(err => console.error(err));
          </script>
        </body>  
      </html>
    

    【讨论】:

    • 谢谢,现在可以了。我现在至少有麦克风按钮,但遇到了一个新问题。当我点击麦克风按钮时,我收到错误:WebSocket 已经处于 CLOSING 或 CLOSED 状态。
    猜你喜欢
    • 2019-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多