Search code examples
reactjsazuretext-to-speech

How do I change the voice in Azure text-to-speech?


I have tried changing my React website to use a UK voice:

const voice = "Microsoft Server Speech Text to Speech Voice (en-GB, LibbyNeural)"
speechConfig.speechSynthesisVoiceName = voice;
speechConfig.speechRecognitionLanguage = "en-GB";
const audioConfig = AudioConfig.fromDefaultMicrophoneInput();

return new SpeechRecognizer(speechConfig, audioConfig);

but all I ever hear is a US voice. What am I missing?


Solution

  • As Ryan has pointed out, you'll want to use the SpeechSynthesizer rather than the SpeechRecognizer. Here's a link to the TTS sample code on github.

    The sample should clear things up and get you going. Be sure to take note of the audioConfig and speechConfig properties. For example, speechSynthesisVoiceName will need a change use the voice name tag as provided here. (Further down that page are standard voices). And speechRecognitionLanguage would be replaced with speechSynthesisLanguage. Those are just a few examples, but the github samples should clear things up all around.

    var audioConfig = sdk.AudioConfig.fromAudioFileOutput(filename);
    var speechConfig = sdk.SpeechConfig.fromSubscription(settings.subscriptionKey, settings.serviceRegion);
    
    // setting the synthesis language, voice name, and output audio format.
    // see https://aka.ms/speech/tts-languages for available languages and voices
    speechConfig.speechSynthesisLanguage = settings.language;
    speechConfig.speechSynthesisVoiceName = "en-US-GuyNeural";
    
    // create the speech synthesizer.
    var synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig);