如何修改认知服务 TTS 示例以播放合成的音频



我正在使用此处提供的 TTS 的 python 示例,它似乎一切正常:

$ python3 python_projects/TTSSample.py
Connect to server to get the Access Token
200 OK
Access Token: eyJ0eXAiOiJKV1QiLCJhMiOiJ1cm46bXMuY29nbml0[truncated]
Connect to server to synthesize the wave
200 OK
The synthesized wave length: 9040

但是,我的期望是直接从我的计算机上听到翻译的文本,但这并没有发生。我错过了任何步骤吗?

我需要做什么才能听到合成文本的有声版本?我正在使用一台 Mac。

您可以使用 Pyaudio 库,您需要先安装它,然后

data = response.read()
conn.close()
print("The synthesized wave length: %d" %(len(data)))
import pyaudio
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16,
                channels=1,
                rate=16000,
                output=True)
stream.write(data)
stream.close()

最新更新