如何在Python中使用IBM Bluemix中的Speech to text和Text to Speech API

时间:2017-03-06 07:37:14

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

我现有的代码是:

const initialState = {
    data: {},
    fetching: false,
    fetched: false,
    error: null
};

const prefillReducer = (state = initialState, action) => {
switch (action.type) {
    case "FETCH_DATA_START":
        return {
            ...state,
            fetching: true
        };
    case "FETCH_DATA_FINISH":
        return {
            ...state,
            data: action.data,
            fetching: false,
            fetched: true
        };
        default:
            return state
    }
};

export default prefillReducer;

但是,我收到以下错误: stauts_code:405(原因:方法不允许)

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

我使用.ogg文件作为音频输入。

1 个答案:

答案 0 :(得分:1)

您正在使用的网址(https://stream.watsonplatform.net/speech-to-text-beta/api/v1/recognize)不再有效,请注意-beta,很久以前就已弃用。你是从哪里得到的?

请您使用以下网址:https://stream.watsonplatform.net/speech-to-text/api/v1/recognize