![]() |
| Picture from Alex Knight @ https://www.pexels.com/ |
After blogging about Azure Speech-to-Text Service, here we have the Text-to-Speech blog. The setup is identical to the Speech-to-Text Service blog. and here is the Python code.
import azure.cognitiveservices.speech as speech_sdk
import os
voices = [
"en-GB-ThomasNeural", # English (United Kingdom)
"en-SG-WayneNeural", # English (Singapore)
"en-US-MonicaNeural", # English (USA)
"en-IN-NeerjaNeural", # Engish (India)
]
text = "To empower every person and every organization on the planet to achieve more."
if __name__ == "__main__":
speech_key, service_region = (
os.environ["AZURE_SPEECH_KEY"],
os.environ["AZURE_SPEECH_LOC"],
)
speech_config = speech_sdk.SpeechConfig(
subscription=speech_key, region=service_region)
audio_config = speech_sdk.audio.AudioOutputConfig(
use_default_speaker=True)
for voice in voices:
# https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support?tabs=stt-tts
speech_config.speech_synthesis_voice_name = voice
speech_synthesizer = speech_sdk.SpeechSynthesizer(
speech_config=speech_config, audio_config=audio_config
)
speech_synthesis_result = speech_synthesizer.speak_text_async(text).get()
if speech_synthesis_result.reason == speech_sdk.ResultReason.Canceled:
cancellation_details = speech_synthesis_result.cancellation_details
raise Error("Speech synthesis canceled: {}".format(cancellation_details.reason))
In the code, we can see that we have 4 voices (UK, Singapore, USA, India) for Microsoft's mission statement.

Comments
Post a Comment