Search code examples
azure-cognitive-servicesspeech

Azure JavaScript TTS-SDK for getting result as an in-memory stream ERROR


audioData: undefined, errorDetails: "Unable to contact server. StatusCode: 500, ErrorDetails: "Unable to contact server. StatusCode: 500, undefin…external_ocsp_ocsp.Agent is not a constructor",

//code
synthesizeSpeech() {
      let that = this;
      const speechConfig = SpeechConfig.fromSubscription(
        "********",
        "********"
      );
      speechConfig.speechSynthesisLanguage = "zh-CN";
      const synthesizer = new SpeechSynthesizer(speechConfig);
      var soundContext = undefined;
      try {
        var AudioContext = window.AudioContext ||window.webkitAudioContext || false;
        if(AudioContext){
          soundContext = new AudioContext();
        }
      } catch (err) {
        console.log(err)
      }
      synthesizer.speakTextAsync(
        "你好你好你好你好你好你好你好.",
        result => {
          console.log(result)
          if(result.audioData && soundContext){
            var source = soundContext.createBufferSource();
            soundContext.decodeAudioData(result.audioData,function(newBuffer){
              source.buffer = newBuffer;
              source.connect(soundContext.destination);
              source.start(0);
            })
          }
          synthesizer.close();
        },
        error => {
          console.log(error);
          synthesizer.close();
        }
      );
    },

Solution

  • This is fixed in Microsoft Azure Cognitive Services Speech SDK for JavaScript v1.12, which will be released recently. You can download the compiled js file after the release or you can compile it from the master of the sdk repo.