Re: speech recognition (144 Views)
Reply
ak New Member
New Member
Posts: 1
Registered: 4 weeks ago
Message 1 of 2 (179 Views)

speech recognition

I have tried running the following code from your website

 

found here : https://gist.github.com/tylernappy/14d5215823c17f3a6dc52ba1677b9f75

 

I keep getting the error : getJobAsyncJobStatus transcription = response['document'][0]['content']
KeyError: 'document'

 

I have seen several other people posting about the exact same issue , with no anwesr. Can someone please clarify this.

 

# install the official Haven OnDemand Python wrapper: https://github.com/HPE-Haven-OnDemand/havenondemand-python
# pip install havenondemand
 
from havenondemand.hodclient import *
client = HODClient("APIKEY", "v1")
 
# params = {'file': 'path/to/file.mp3'} # if using a local file
params = {'url': 'https://www.havenondemand.com/sample-content/videos/hpnext.mp4'} # if using a publicly facing URL
response_async = client.post_request(params, HODApps.RECOGNIZE_SPEECH, async=True)
jobID = response_async['jobID']
 
def getJobAsyncJobStatus(jobID):
print 'Processing...'
response = client.get_job_status(jobID)
if response == None: # still transcribing...
getJobAsyncJobStatus(jobID)
else: # done trasncribing
transcription = response['document'][0]['content']
print transcription
 

getJobAsyncJobStatus(jobID)

Highlighted
Level 2
Posts: 7
Registered: ‎06-19-2014
Message 2 of 2 (144 Views)

Re: speech recognition

That example code doesn't work because it is incorrectly checking if the job has completed before attempting to extract the transcription.

 

The following example code, which is a slightly modified version of another example https://github.com/HPE-Haven-OnDemand/havenondemand-python/blob/master/examples/entityextraction_dem..., shows one way of calling the Recognize Speech V2 API.

 

Note that you will need to replace "API-KEY" with your actual API key on line 4. If you want to use this with the Recognize Speech V1 API change "v2" on the same line to "v1", rename the "language_model" parameter to "language" and modify the "requestCompleted" function to deal with the different response that is returned.

 

 

 

from havenondemand.hodclient import *
from havenondemand.hodresponseparser import *

hodClient = HODClient("API-KEY", "v2")
parser = HODResponseParser()

# callback function
def requestCompleted(response, **context):
    text = ""
    payloadObj = parser.parse_payload(response)
    if payloadObj is None:
        errorObj = parser.get_last_error()
        for err in errorObj.errors:
            if err.error == ErrorCode.QUEUED or err.error == ErrorCode.IN_PROGRESS:
                # wait for some time then call GetJobStatus or GetJobResult again with the same jobID from err.jobID
                print (err.reason)
                time.sleep(5)
                hodClient.get_job_status(err.jobID, requestCompleted)
            else:
                text += "Error code: %d \nReason: %s \nDetails: %s\n" % (err.error,err.reason, err.detail)
    else:
        items = payloadObj["items"]
        for item in items:
            text += item["text"] + " "
    print (text)

def asyncRequestCompleted(response, **context):
    jobID = parser.parse_jobid(response)
    if jobID is None:
		errorObj = parser.get_last_error()
		for err in errorObj.errors:
			print ("Error code: %d \nReason: %s \nDetails: %s\n" % (err.error,err.reason, err.detail))
    else:
        hodClient.get_job_result(jobID, requestCompleted, **context)


paramArr = {}
paramArr["url"] = "https://www.havenondemand.com/sample-content/videos/hpnext.mp4"
paramArr["language_model"] = "en-us"

hodClient.post_request(paramArr, HODApps.RECOGNIZE_SPEECH, async=True, callback=asyncRequestCompleted)

 

† 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