Using Speech Recognition API with Python 2.7 gives KeyError on document (332 Views)
Reply
New Member
Posts: 1
Registered: ‎03-18-2017
Message 1 of 1 (332 Views)

Using Speech Recognition API with Python 2.7 gives KeyError on document

Hi,

 

I am trying to use the Speech Recognition API with Python 2.7 and I was trying the code from github, but its giving me the folloewing error:

 

"...

transcription = response['document'][0]['content']
KeyError: 'document'"

 

The code is as below:

 

from havenondemand.hodclient import *
client = HODClient(MY_API, "v1")

def getJobAsyncJobStatus(jobID):
    print 'Processing...'
    response = client.get_job_status(jobID)
    if response == None: # still transcribing...
        getJobAsyncJobStatus(jobID)
    else: # done trasncribing
        print response
        transcription = response['document'][0]['content']
        print transcription
        return transcription

file = "<Somefile>.mp4"
params = {'file': file}
response_async = client.post_request(params, HODApps.RECOGNIZE_SPEECH, async=True)
jobID = response_async['jobID']
output = getJobAsyncJobStatus(jobID)

Can anyone help me with where I am going wrong?

† The opinions expressed above are the personal opinions of the authors, not of HPE. By using this site, you accept the Terms of Use and Rules of Participation