Reputation: 3
I am trying to make a python script which takes a '.wav' file and returns the text. So i did this:
import httplib
import json
import sys
def speech_to_text(audio):
url = 'www.google.com'
path = '/speech-api/v2/recognize?client=chromium&maxresults=1&pfilter=2&xjerr=1&lang=en-US&key=AIzaSyBdMw04YuFYZAqaUbOlp_85PZWXFTyoz10'
# path = '/tag/?client=chromium&xjerr=1&lang=en-US&key=AIzaSyAovcASpSCspTHTRXAF5pSzIl4BrBILOSY'
headers = {"Content-type": "audio/x-flac; rate=16000"}
# params = {"": "1", "client": "chromium"}
conn = httplib.HTTPSConnection(url)
conn.request("POST", path, audio, headers)
response = conn.getresponse()
print (response)
data = response.read()
print (data)
jsdata = json.loads(data)
# return jsdata["hypotheses"][0]["utterance"]
# return jsdata["hypotheses"][0]["utterance"]
return jsdata
but everytime it returns this :
{"result":[]}
I am using python2.7 on Ubuntu 14.04.
What should i do ?
Upvotes: 0
Views: 588
Reputation: 7243
You're sending a wav file but your POST says it's a FLAC? (audio/x-flac)
You will want to convert the .WAV to .FLAC before requesting google to transcribe it.
Upvotes: 1