anindya
anindya

Reputation: 13

How to use Speech to text and Text to Speech APIs from IBM Bluemix in Python

My existing code is:

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

However, I am getting the following error: stauts_code: 405 (reason: Method Not Allowed)

{
  "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"
}

I am using an .ogg file as audio input.

Upvotes: 0

Views: 469

Answers (1)

Daniel Bolanos
Daniel Bolanos

Reputation: 795

the url you are using (https://stream.watsonplatform.net/speech-to-text-beta/api/v1/recognize) is no longer valid, notice the -beta, it was deprecated long time ago. Where did you get it from?

Can you please use the following url: https://stream.watsonplatform.net/speech-to-text/api/v1/recognize

Upvotes: 1

Related Questions