python - 在 bluemix 上使用 python 调用服务

标签 python ibm-cloud text-to-speech ibm-watson

我在 IBM Bluemix 平台上使用 python。如何调用文本转语音 Watson 服务?我的 python 代码中有字符串,我需要传递此文本以供阅读。

最佳答案

假设您已经拥有一个 Bluemix 帐户并将文本转语音 Watson API 添加到您的 Bluemix 工作区,您拥有访问该 API 的凭据(restful)。

如果您请求使用 CURL linux 应用程序,它将是这样的

curl -u "xxxxx729-b03f-4403-8adf-c5418ee4ea05":"xxxxxiWtmVoG" "https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?text=Hello+World" -H "accept: audio/flac" > sound.flac

使用Python,可以

import requests

headers = {'accept': 'audio/flac'}

r = requests.get('https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?text=Hello+World', auth=('xxxxx729-b03f-4403-8adf-c5418ee4ea05', 'xxxxxiWtmVoG'), headers=headers)

with open('/home/leo/sound.flac', 'wb') as fd:
    for chunk in r.iter_content(1024):
        fd.write(chunk)

参见 http://docs.python-requests.org/en/master/user/quickstart/有关请求包的详细信息。

参见 https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/text-to-speech/api/v1/用于 text2Speech 文档。

关于python - 在 bluemix 上使用 python 调用服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35820579/

相关文章:

java - 使用 IVONA 文本转语音的 AWS Java NoSuchMethodError

python - 如何让 Python 说话

python - 从命令行运行脚本时,忽略 sklearn Gridsearch 中 n_jobs = -1 的警告,不适用于 warnings.simplefilter ('ignore' )

database - 部署构建应用程序并将其连接到 Bluemix PaaS?

python - Rapids CUML 随机森林回归模型推理

java - 从 bluemix 上的 Boilerplates Java DB Web Starter 示例代码更改表

ibm-cloud - IBM Bluemix 注册表推送身份验证错误

javascript - SpeechSynthesis.speaking 从不真实

python - 在python中同步多个线程

Python 导入带有多个分隔符的数据