title: Azure text-to-voice: how can I change language and voice for output?
body: <p>I need help for the following JavaScript and hope someone can kindly help me. Text is read out in an English voice.</p>
  <p>How can I change language and voice within the following working code? I intensively searched the web but couldn't find a suitable solution due to my poor java skills.</p>
  <p>So, unfortunately my programming skills are not good enough, so I need some assistance for a concrete line of code. Thanks.</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
    &lt;title&gt;Microsoft Cognitive Services Speech SDK JavaScript Quickstart&lt;/title&gt;
    &lt;meta charset=&quot;utf-8&quot; /&gt;
  &lt;/head&gt;
  &lt;body&gt;
    
    &lt;button id=&quot;startSpeakTextAsyncButton&quot;&gt;speak&lt;/button&gt;
    
    &lt;!-- Speech SDK reference sdk. --&gt;
    &lt;script src=&quot;microsoft.cognitiveservices.speech.sdk.bundle.js&quot;&gt;&lt;/script&gt;
  
    &lt;!--   Speech SDK Authorization token  --&gt;
    &lt;script&gt;
    var authorizationEndpoint = &quot;token.php&quot;;
  
    function RequestAuthorizationToken() {
      if (authorizationEndpoint) {
        var a = new XMLHttpRequest();
        a.open(&quot;GET&quot;, authorizationEndpoint);
        a.setRequestHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);
        a.send(&quot;&quot;);
        a.onload = function() {
          var token = JSON.parse(atob(this.responseText.split(&quot;.&quot;)[1]));
          serviceRegion.value = token.region;
          authorizationToken = this.responseText;
          subscriptionKey.disabled = true;
        }
      }
    }
    &lt;/script&gt;
  
    &lt;!-- Speech SDK USAGE --&gt;
    &lt;script&gt;
      var startSpeakTextAsyncButton;
      var serviceRegion = &quot;westeurope&quot;; 
      // for testing:
      // var voiceName = &quot;HeddaRUS&quot;;
      // var voiceLanguage =&quot;de-DE&quot;;
  
      var subscriptionKey;
      var authorizationToken;
      var SpeechSDK;
      var synthesizer;    
  
      document.addEventListener(&quot;DOMContentLoaded&quot;, function () {
        startSpeakTextAsyncButton = document.getElementById(&quot;startSpeakTextAsyncButton&quot;);
        subscriptionKey = document.getElementById(&quot;subscriptionKey&quot;);
        
          startSpeakTextAsyncButton.addEventListener(&quot;click&quot;, function () {
          startSpeakTextAsyncButton.disabled = true;
          
          speechConfig = SpeechSDK.SpeechConfig.fromAuthorizationToken(authorizationToken, serviceRegion);  
              
          // I don't know how the code should looke like:
          // speechConfig = SpeechSDK.SpeechConfig.setSpeechSynthesisLanguage(voiceLanguage);
          // speechConfig = SpeechSDK.SpeechConfig.setSpeechSynthesisVoiceName(voiceName);
              
          synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig);
  
          // output should be in German language:    
          let inputText = &quot;Ich möchte es auf deutsche Sprache setzen, weiß aber nicht wie!&quot;;
                  
          synthesizer.speakTextAsync(
            inputText,
            function (result) {
              startSpeakTextAsyncButton.disabled = false;
              window.console.log(result);
              synthesizer.close();
              synthesizer = undefined;
            });
        });
  
        if (!!window.SpeechSDK) {
          SpeechSDK = window.SpeechSDK;
          startSpeakTextAsyncButton.disabled = false;
          if (typeof RequestAuthorizationToken === &quot;function&quot;) {RequestAuthorizationToken();}
        }
      });
    
    &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>