scenario:
I am sending a _long_ speech recognition file for speech recognition.
operation = client.long_running_recognize(config, audio)
operation_name = operation._operation.name
There is another file where I have to use operation_name (returned by google speech API) to get back the response again.
I tried get_operation method of the "Long-Running Operations Client":
from google.api_core import operations_v1
api = operations_v1.OperationsClient()
name = ...
response = api.get_operation(name)
but I get the following error:
----> 1 api = operations_v1.OperationsClient()
TypeError: __init__() missing 1 required positional argument: 'channel'
From the SO. Looks like you also need to add the channel.
from google.cloud import speech
client = speech.SpeechClient()
from google.api_core import operations_v1
api = operations_v1.OperationsClient(client.transport.channel)
name = ...
response = api.get_operation(name)
Let me know if that doesn't fix the issue.
yes, thanks @nnegrey , this solved the problem indeed
@nnegrey the response in coming in bytes and is not even getting converted to string format ,
I not sure of encoding type too to convert it to string
I tried with utf-8 but it results in error
'utf-8' codec can't decode byte 0xdc in position 1: invalid continuation byte
Got it, from:
response = api.get_operation(name)
print(response.response.type_url) # This should be a LongRunningRecognizeResponse object
long_running_recognize_response = client.types.LongRunningRecognizeResponse()
long_running_recognize_response.ParseFromString(response.response.value)
for result in long_running_recognize_response.results:
# The first alternative is the most likely one for this portion.
print(u'Transcript: {}'.format(result.alternatives[0].transcript))
print('Confidence: {}'.format(result.alternatives[0].confidence))
Thanks again @nnegrey
I just login to thankyou @nnegrey !
I already take 3 days trying to parse this data.
Thank you very much!!!
From the SO. Looks like you also need to add the
channel.from google.cloud import speech client = speech.SpeechClient() from google.api_core import operations_v1 api = operations_v1.OperationsClient(client.transport.channel) name = ... response = api.get_operation(name)
@nnegrey I tried this but I'm getting this error. Any ideas how to solve it?
'SpeechClient' object has no attribute 'transport'
Most helpful comment
Got it, from: