Azure Speech service Text to speech lag

Kaushik Raju 1 Reputation point
2022-02-15T12:59:01.877+00:00

I am using the azure tts in javascript and i am facing an issue of latency .. I have to create a new instance of speechsynthesizer everytime i have to play audio from the speaker ..is there no way to stop audio from being played other than synthesizer.close() ?? below is the code i am using and its causing the audio to lag and its choppy at times ..could anyone point out why this is happening ..

function textToSpeech(txt){

window.tts_flag = 1;
var player = new SpeechSDK.SpeakerAudioDestination();
player.onAudioEnd = function (_) {
    window.tts_flag = 0;
  };
var audioConfig  = SpeechSDK.AudioConfig.fromSpeakerOutput(player);
const speechConfig = SpeechSDK.SpeechConfig.fromSubscription("");  

var synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig, audioConfig);
const complete_cb = function (result) {

  synthesizer.close();
  synthesizer = undefined;
};
const err_cb = function (err) {
  window.console.log(err);
  synthesizer.close();
  synthesizer = undefined;
};
synthesizer.speakTextAsync(txt,
  complete_cb,
  err_cb); 

}
if (!!window.SpeechSDK) {SpeechSDK = window.SpeechSDK;}

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
2,069 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,628 questions
{count} votes

1 answer

Sort by: Most helpful
  1. YutongTie-MSFT 53,971 Reputation points Moderator
    2022-02-28T10:43:09.763+00:00

    Hello @Kaushik Raju

    I hope you have solved the issue. Since we did not receive your response and we were not able to reproduce the issue, we want to do a double check to see if you still need help. Please let us know if you are still blocked by this issue.

    For your reference, this is the document for quick start:
    https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=script%2Cbrowserjs%2Cwindowsinstall&pivots=programming-language-javascript

    JS code sample: https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/samples/js/browser

    I hope this helps, please let us know if you have further concern, we are glad to help.

    Regards,
    Yutong

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.