操作系统类型和版本:
Windows 10, build 16199.1000
Python版本和虚拟环境信息
python --version
:Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
谷歌云蟒版本:
google-cloud-speech==0.27.0
堆栈跟踪:
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'
重现步骤:
当我使用这个时:
alternatives = operation.result().results[0].alternatives
for alternative in alternatives:
print('Transcript: {}'.format(alternative.transcript))
print('Confidence: {}'.format(alternative.confidence))
它按预期工作,但只打印第一个成绩单。当我使用这个时:
res = operation.result().results
print(res, file=sys.stderr)
print('. '.join(resp.alternative.transcript for resp in res), file=sys.stderr)
我得到了上面的例外。我也试过print('. '.join(resp.transcript for resp in res), file=sys.stderr)
and print('. '.join(resp.alternative for resp in res), file=sys.stderr)
,就像打印调试一样。AttributeError
两者都对任一属性抛出一个。
完整的工作示例:https ://gist.github.com/mxplusb/8f487a6ff3c781689799bb7ce1dec3f3 。它以正确的格式从视频文件中删除音频ffmpeg
,将其上传到 GCS,然后执行异步语音到文本识别。我正在尝试将所有成绩单连接成一个大文本字符串。