首页 > 解决方案 > 在 Directline 4.0 网络聊天中集成认知语音

问题描述

在此处输入图像描述以前V3.0我使用此代码并将其Bot.App作为参数传递,但我不知道如何在 DirectlineV4.0中使用Webchat-E5.js

const speechOptions = {
        speechRecognizer: new CognitiveServices.SpeechRecognizer({ locale: 'de-DE', subscriptionKey: '1add78901d9d' }),
        speechSynthesizer: new CognitiveServices.SpeechSynthesizer({
            gender: CognitiveServices.SynthesisGender.Female,
            subscriptionKey: '1add78125a901d9d',
            voiceName: 'Microsoft Server Speech Text to Speech Voice (de-DE, Stefan, Apollo)'
        })
    };

提前谢谢了。

文本到语音无法与认知 Bing API 一起使用。

 window.fetch('https://sfbotspeech.cognitiveservices.azure.com/sts/v1.0/issuetoken', { method: 'POST', headers: {
                            'Ocp-Apim-Subscription-Key' : 'f9d649bf33bf2427c', 'Content-type': 'application/x-www-form-urlencoded' , 'Content-Length': '0'} })
         .then(function (res) {
          return res.text();
        })        
        .then(function (authtok) {
              SpeechToken =  authtok;

        console.log(SpeechToken)    ;
        const webSpeechPonyfillFactory =  WebChat.createCognitiveServicesSpeechServicesPonyfillFactory({
           authorizationToken: SpeechToken
         });

        ///
        WebChat.renderWebChat(
            {
                bot: bot,
                directLine: WebChat.createDirectLine({token}),
                user: user,
                //speechOptions: speechOptions,
                resize: 'detect',
                styleOptions: styleOptions,
                selectVoice: (activity) =>
                    activity.locale === 'de-DE',
                webSpeechPonyfillFactory : webSpeechPonyfillFactory
            },
            document.getElementById('BotChatGoesHere')          
        );

标签: botframeworkspeech-recognition

解决方案


查看位于 BotFramework-WebChat 存储库中的示例06.g.select-voice 。附件index.html显示了完整的代码。

上面的示例扩展了示例06.c.cognitive-services-speech-services-js。如果您需要其他指导,请考虑查看此指南。

希望有帮助!


推荐阅读