The first TTS in the universe Microsoft ASZURE python api demo

I am a person who pursues quality. There are a lot of tts available, and there are also a lot of free ones, but Microsoft is currently the only one in the world, and the tts website seems to have canceled the free prostitution mechanism recently. Using an account is not expensive, 40 a year.
The simple method of use is here, of course, is the homework copied from the Microsoft document:
it is known that it can be read directly through the speaker, of course, it can also be converted into audio files in various formats and downloaded. Genuine users are comfortable

import os
import azure.cognitiveservices.speech as speechsdk

# This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
speech_config = speechsdk.SpeechConfig(subscription='xxxxx', region='eastasia')
audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True)

# The language of the voice that speaks.
speech_config.speech_synthesis_voice_name='zh-CN-XiaochenNeural'

speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)

# Get text from the console and synthesize to the default speaker.
print("gogogo")
text ='''
最近看上了两款开发板。
'''
audio_config = speechsdk.audio.AudioOutputConfig(filename="jd.wav")
speech_config.speech_synthesis_language = "eastasia" 
speech_config.speech_synthesis_voice_name ="zh-CN-XiaochenNeural"
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)

speech_synthesis_result = speech_synthesizer.speak_text_async(text).get()


if speech_synthesis_result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
    print("Speech synthesized for text [{}]".format(text))
elif speech_synthesis_result.reason == speechsdk.ResultReason.Canceled:
    cancellation_details = speech_synthesis_result.cancellation_details
    print("Speech synthesis canceled: {}".format(cancellation_details.reason))
    if cancellation_details.reason == speechsdk.CancellationReason.Error:
        if cancellation_details.error_details:
            print("Error details: {}".format(cancellation_details.error_details))
            print("Did you set the speech resource key and region values?")

Guess you like

Origin blog.csdn.net/jd3096/article/details/130438041