微软Azure

https://portal.azure.com/ 注册后绑定visa卡

TTS微软Azure_Azure

创建微软语音服务

创建资源

TTS微软Azure_Azure_02


选择AI应用和代理 -》 语音

TTS微软Azure_microsoft_03


输入语音服务必填项

TTS微软Azure_Python_04


然后点击创建

TTS微软Azure_Azure_05


创建完成后如下

TTS微软Azure_Python_06


点击转到资源

语音服务

TTS微软Azure_Python_07


点击转到SpeechStudio

TTS微软Azure_microsoft_08


语音库

TTS微软Azure_Python_09


没有有声内容创作,切换到旧外观

TTS微软Azure_microsoft_10


出现有声内容创作

TTS微软Azure_Python_11

SDK

开发文档:
https://learn.microsoft.com/en-us/azure/ai-services/speech-service/get-started-text-to-speech?tabs=macos&pivots=programming-language-csharp Github示例代码:
https://github.com/Azure-Samples/cognitive-services-speech-sdk

Python代码调用

VSCode下载Azure AI Speech Toolkit

TTS微软Azure_Python_12

Python代码调用API

安装azure包

pip install azure-cognitiveservices-speech
import os
import azure.cognitiveservices.speech as speechsdk

# This example requires environment variables named "SPEECH_KEY" and "ENDPOINT"
# Replace with your own subscription key and endpoint, the endpoint is like : "https://YourServiceRegion.api.cognitive.microsoft.com"
speech_config = speechsdk.SpeechConfig(subscription=os.environ.get('SPEECH_KEY'), endpoint=os.environ.get('ENDPOINT'))
audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True)

# The neural multilingual voice can speak different languages based on the input text.
speech_config.speech_synthesis_voice_name='zh-CN-XiaoxiaoNeural'

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

# Get text from the console and synthesize to the default speaker.
print("Enter some text that you want to speak >")
text = input()

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 endpoint values?")

如果这篇文章对你有用,可以关注本人微信公众号获取更多ヽ(^ω^)ノ ~

TTS微软Azure_Azure_13