正如我所说的已经对标题感到抱歉。我从未使用过 Azure API,也不知道代码有什么问题,因为我只是从文档中复制并输入了我的信息。
这是代码:
from azure.cognitiveservices.speech import AudioDataStream, SpeechConfig, SpeechSynthesizer, SpeechSynthesisOutputFormat
from azure.cognitiveservices.speech.audio import AudioOutputConfig
speech_config = SpeechConfig(subscription="ImagineHereAreNumbers", region="westeurope")
speech_config.speech_synthesis_language = "en-US"
speech_config.speech_synthesis_voice_name = "ChristopherNeural"
audio_config = AudioOutputConfig(filename=r'C:\Users\TheD4\OneDrive\Desktop\SpeechFolder\Azure.wav')
synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
synthesizer.speak_text_async("A simple test to write to a file.")
好吧,当我运行它时,我没有收到任何错误,事实上,在我想要的文件夹中获取了一个 .wav 文件,但是这个文件有 0 个字节并且看起来已损坏。
现在这就是为什么我不知道出了什么问题,因为如果我删除它
speech_config.speech_synthesis_language = "en-US"
speech_config.speech_synthesis_voice_name = "ChristopherNeural"
所以变成了这个
from azure.cognitiveservices.speech import AudioDataStream, SpeechConfig, SpeechSynthesizer, SpeechSynthesisOutputFormat
from azure.cognitiveservices.speech.audio import AudioOutputConfig
speech_config = SpeechConfig(subscription="ImagineHereAreNumbers", region="westeurope")
audio_config = AudioOutputConfig(filename=r'C:\Users\TheD4\OneDrive\Desktop\SpeechFolder\Azure.wav')
synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
synthesizer.speak_text_async("A simple test to write to a file.")
它现在突然起作用了,但我认为它是基本/常见的声音。
所以这是我的问题:我如何选择我想要的声音(顺便说一句,这是“en-US-JennyNeural” style="customerservice" 还是这些行中的某个)
先感谢您!