python - 使用 IBM Watson 进行文本转语音的简单 Python 代码
问题描述
我一直在寻找可以帮助我在 pycharm 中使用 ibm watson 进行文本转语音的代码。请尽快帮助我
解决方案
您可以在IBM Watson 文档中找到大部分代码
首先,您需要安装 ibmwatson 软件包,然后您需要通过API 密钥和 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)
推荐阅读
- linux - 如何将包含“D,1”、“D,2”或“D,3”的 csv 文件中的行复制到 txt 文件中,其中解决方案与 csv 文件的顺序相同
- java - 无法使用spring boot从yaml文件加载属性
- android - 如何使用 Hilt 访问 attachBaseContext 中的注入属性?
- node.js - 如何从电子js应用程序调用spring boot rest服务
- c++ - 非捕获 lambda 生命周期
- android - 如何在溢出菜单上设置点击监听器 - 材质工具栏
- reactjs - 如何在 Facebook Auth 上正确处理长寿令牌
- javascript - 如何使用 react-native 创建文件扩展名?
- python - 试图抓取页面,但缺少
- python - Django对外部属性求和