0

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 ?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.