2016-03-05 77 views
4

我使用的是IBM Bluemix平臺上調用的Python與Python的服務。我怎樣才能撥打文字轉語音Watson服務?我有我的Python代碼中的字符串,我需要通過這個文本來閱讀。上bluemix

+2

見https://github.com/watson-developer-cloud/text-to-speech-python爲入門示例應用程序 –

回答

3

假設你已經有了一個Bluemix帳戶,並添加文本到語音沃森API到你的工作空間Bluemix,你要訪問API(寧靜)的憑據。

如果您正在使用捲曲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文檔。

+2

謝謝你這麼多@Leo ...一切你在這裏解釋是非常有用的...這是我需要開始... –

+1

那麼怎麼樣upvoting答案或標記它作爲正確的答案?只是一個想法。 ;-) –