我一直在寻找可以帮助我在pycharm中使用ibm watson进行文本转语音的代码。请尽早帮助我
你可以在 IBM Watson 文档
首先你需要安装ibmwatson包,然后你需要通过以下方式验证自己的身份 API密钥 和网址。只有在您建立了连接之后,您才可以调用 synthesize
职能。
pip install --upgrade "ibm-watson>=4.4.0"
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('filename.wav','wb') as audio_file:
audio_file.write(text_to_speech.synthesize('hello world',voice='en-US_Henry3Voice',accept='audio/mp3').get_result().content)