Search code examples
botframeworkchatbotdirect-line-botframework

How to change the Language in Direct Line for Voice Input? C#


Hi so the default language is English and I want to change to German. I currently use Option 3 but it's still not working. What's wrong?

<script
> src="https://cdn.botframework.com/botframework-webchat/latest/CognitiveServices.js"></script>
> <script>
>     const params = BotChat.queryParams(location.search);
>     const user = {
>         id: params['userid'] || 'userid',
>         name: params['username'] || 'username'
>     };
> 
>     const bot = {
>         id: params['botid'] || 'botid',
>         name: params['botname'] || 'botname'
>     };
> 
>     window.botchatDebug = params['debug'] && params['debug'] === 'true';
>     
>     const speechOptions =
>  
>       speechRecognizer: new CognitiveServices.SpeechRecognizer({ SpeechRecognitionLanguage: 'de-de', subscriptionKey: 'xxxxx' }),
>         speechSynthesizer: new CognitiveServices.SpeechSynthesizer({
>         locale: 'de-de',
>         gender: CognitiveServices.SynthesisGender.Female,
>         subscriptionKey: 'xxxxxxx',
>         voiceName: 'Microsoft Server Speech Text to Speech Voice (de-DE, KatjaNeural)'
>       })
>     };
>     BotChat.App({
>         bot: bot,
>         locale: params['de-DE'],
>         resize: 'detect',
> 
>         speechOptions: speechOptions,
>         user: user,
> 
>         directLine: {
>             domain: params['domain'],
>             secret: params['s'],
>             token: params['t'],
>             webSocket: params['webSocket'] && params['webSocket'] === 'true' // defaults to true
>         }
>     }, document.getElementById('BotChatGoesHere')); </script> </body> </html>

Any ideas or code to fix my problem?


Solution

  • Solved it.

    1. Add Direct Line Speech Channel in Azure to your Speech Cognitive Service.
    2. Add Language Parameters like this:

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

    Now the bot is listening to German Lang in WebChat as well as the above mentioned params to 'de-DE'.