0

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.

Petter Friberg
  • 19,652
  • 9
  • 51
  • 94
anindya
  • 13
  • 2
  • 2
    have you tried with `response = requests.get(url, ....)` – Bijoy Mar 06 '17 at 07:46
  • You might need to use a `requests.Session` object to first login (using `post`), and then get the data you want using `get`. See [this answer](http://stackoverflow.com/questions/11892729/how-to-log-in-to-a-website-using-pythons-requests-module/17633072#17633072), to [How to “log in” to a website using Python's Requests module?](http://stackoverflow.com/questions/11892729/how-to-log-in-to-a-website-using-pythons-requests-module/17633072) – Peter Wood Mar 06 '17 at 08:17

1 Answers1

1

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

Daniel Bolanos
  • 760
  • 3
  • 6