如何在Python中使用IBM Bluemix的语音到文本和文本到语音API
我现有的代码是:如何在Python中使用IBM Bluemix的语音到文本和文本到语音API,python,ibm-cloud,text-to-speech,speech-to-text,watson,Python,Ibm Cloud,Text To Speech,Speech To Text,Watson,我现有的代码是: import requests import json import os url = "https://stream.watsonplatform.net/speech-to-text-beta/api/v1/recognize" username= "USERNAME" password= "PASSWORD" filepath = '/home/user/myfamily.ogg' # path to file filename = os.path
import requests
import json
import os
url = "https://stream.watsonplatform.net/speech-to-text-beta/api/v1/recognize"
username= "USERNAME"
password= "PASSWORD"
filepath = '/home/user/myfamily.ogg' # path to file
filename = os.path.basename(filepath)
audio = open(filepath,'rb')
files_input = {
"audioFile":(filename,audio,'audio/ogg')
}
response = requests.post(url, auth=(username, password), headers={"Content-Type": "audio/wav"},files=files_input)
print('stauts_code: {} (reason: {})'.format(response.status_code, response.reason))
print response.text
但是,我得到以下错误:
stauts_代码:405(原因:不允许使用方法)
我正在使用.ogg文件作为音频输入。您正在使用的url(https://stream.watsonplatform.net/speech-to-text-beta/api/v1/recognize
)不再有效,请注意-beta
,它早就被弃用了。你从哪里弄来的
您可以使用以下url:
https://stream.watsonplatform.net/speech-to-text/api/v1/recognize
您是否尝试过response=requests.get(url,…)
您可能需要使用requests.Session
对象首次登录(使用post
),然后使用get
获取所需数据。看,到
{
"error": "Your browser approached me (at /text-to-speech/api) with the method \"POST\". I only allow the methods HEAD, GET here.",
"code": 405,
"code_description": "Method Not Allowed"
}