OS type and version:
Windows 10, build 16199.1000Python version and virtual environment information
python --version:Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32google-cloud-python version:
google-cloud-speech==0.27.0
Stack Trace:
Exception in thread Thread-2:
Traceback (most recent call last):
File "C:\Python27\Lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "C:\Python27\Lib\threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "E:/Programming/Python/untitled1/main.py", line 109, in get_transcript
print('. '.join(resp.alternative.transcript for resp in res), file=sys.stderr)
File "E:/Programming/Python/untitled1/main.py", line 109, in <genexpr>
print('. '.join(resp.alternative.transcript for resp in res), file=sys.stderr)
AttributeError: 'SpeechRecognitionResult' object has no attribute 'alternative'
Steps to reproduce:
When I use this:
alternatives = operation.result().results[0].alternatives
for alternative in alternatives:
print('Transcript: {}'.format(alternative.transcript))
print('Confidence: {}'.format(alternative.confidence))
It works as intended, but only prints the first transcript. When I use this:
res = operation.result().results
print(res, file=sys.stderr)
print('. '.join(resp.alternative.transcript for resp in res), file=sys.stderr)
I get the exception above. I have also tried print('. '.join(resp.transcript for resp in res), file=sys.stderr) and print('. '.join(resp.alternative for resp in res), file=sys.stderr), just as print debugging. Both throw an AttributeError on either attribute.
Complete working example: https://gist.github.com/mxplusb/8f487a6ff3c781689799bb7ce1dec3f3.
It removes the audio from a video file using ffmpeg in the proper format, uploads it to GCS, and then performs an asynchronous speech-to-text recognition. I am trying to concatenate all the transcripts into one large text string.