宇宙第一TTS 微软ASZURE python api演示

文章讲述了如何利用微软的Azure认知服务进行文本到语音(TTS)转换,特别是通过PythonSDK实现语音合成,并提到服务可能需要购买订阅。示例代码展示了设置语音合成参数和保存音频文件的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我是个追求品质的人,tts可用的一大堆,免费的也一大堆,但是微软的目前独步天下,而且近期tts网站似乎取消了白嫖机制,只能正经八百白买了,去TB搞一个使用账号,也不贵,一年40。
简单的使用方法在此,当然,就是从微软文档抄的作业:
目前已知可以直接通过扬声器读出来,当然也可以转成各种格式的音频文件下载下来,正版用户就是舒服

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?")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值