【问题标题】:Calling a service with python on bluemix在 bluemix 上使用 python 调用服务
【发布时间】:2016-06-19 15:16:01
【问题描述】:

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

【问题讨论】:

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


【解决方案1】:

假设您已经拥有一个 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/

有关 text2Speech 文档,请参阅 https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/text-to-speech/api/v1/

【讨论】:

  • 非常感谢@Leo...您在这里解释的一切都非常有用...这是我需要开始...
  • 那么如何支持答案或将其标记为正确答案?只是一个想法。 ;-)
【解决方案2】:

最好的办法是使用Watson Developer Cloud Python SDK

【讨论】:

    猜你喜欢
    • 2016-05-19
    • 2016-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多