Microsoft Bot Framework语音识别网络聊天集成

时间:2020-01-19 23:51:34

标签: javascript botframework speech-recognition web-chat

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

但是我总是会收到错误:未捕获的SyntaxError:在行上出现意外的标识符...

,错误行为: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();

1 个答案:

答案 0 :(得分:0)

尝试一下:

 <!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>