TheComputerMan/Azure-Speech
0
1import random2from azure.cognitiveservices.speech import (3 AudioDataStream,4 SpeechConfig,5 SpeechSynthesizer,6 SpeechSynthesisOutputFormat,7)8 9# Subscription settings from Azure10# Region can be westeurope for example11subscription_key = "[AZURE_SPEECH_API_KEY]"12subscription_region = "[AZURE_SPEECH_API_REGION]"13 14# Input SSML file15# Open this file to change or fine-tune the pitch, pronunciation, speaking rate, volume, voice, language and more16# https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/cognitive-services/Speech-Service/language-support.md#neural-voices17input_file = "ssml.xml"18 19# https://docs.microsoft.com/nl-nl/python/api/azure-cognitiveservices-speech/azure.cognitiveservices.speech.speechsynthesisoutputformat?view=azure-python20audio_format = "Riff24Khz16BitMonoPcm"21 22# Output folder and file23output_file = f"file-{random.randint(10000,99999)}.wav"24 25speech_config = SpeechConfig(subscription=subscription_key, region=subscription_region)26speech_config.set_speech_synthesis_output_format(27 SpeechSynthesisOutputFormat[audio_format]28)29synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=None)30 31input = open(f"{input_file}", "r").read()32result = synthesizer.speak_ssml_async(input).get()33 34stream = AudioDataStream(result)35stream.save_to_wav_file(f"{output_file}")36 