【发布时间】:2020-04-10 05:47:50
【问题描述】:
我正在编写一个简单的 python 程序,它获取一个文本文件,然后使用 IBM Watson Text To Speech 将其转换为音频,然后使用 playsound 等模块直接播放音频。
大多数教程都向您展示了如何将结果仅保存到文件中,而不是如何将结果传递给模块以播放音频
from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('{apikey}')
text_to_speech = TextToSpeechV1(
authenticator=authenticator
)
text_to_speech.set_service_url('{url}')
with open('hello_world.wav', 'wb') as audio_file:
audio_file.write(
text_to_speech.synthesize(
'Hello world',
voice='en-US_AllisonVoice',
accept='audio/wav'
).get_result().content)
这不是我想要的,我希望能够播放音频而不保存它,我该怎么做。
【问题讨论】:
标签: python ibm-cloud text-to-speech ibm-watson watson-text-to-speech