我一直在寻找可以在pycharm中使用ibm watson在文本到语音中帮助我的代码。请尽快帮助我
您可以在IBM Watson Documentation中找到大部分此代码
首先,您需要安装ibmwatson软件包,然后需要通过API Key和url进行身份验证。只有建立连接后,才能调用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)