OS Typ und Version:
Windows 10, build 16199.1000
Attribute auf Transkript Ergebnisse von Google Speech APIPython-Version und virtuelle Umgebung Informationen
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-Python-Version:
google-cloud-speech==0.27.0
Stapel:
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'
Schritte zum Reproduzieren:
Wenn ich dies:
alternatives = operation.result().results[0].alternatives
for alternative in alternatives:
print('Transcript: {}'.format(alternative.transcript))
print('Confidence: {}'.format(alternative.confidence))
Es wie beabsichtigt funktioniert, aber nur druckt die erste Transkript. Wenn ich dies verwende:
res = operation.result().results
print(res, file=sys.stderr)
print('. '.join(resp.alternative.transcript for resp in res), file=sys.stderr)
Ich bekomme die Ausnahme oben. Ich habe auch versucht print('. '.join(resp.transcript for resp in res), file=sys.stderr)
und print('. '.join(resp.alternative for resp in res), file=sys.stderr)
, genauso wie Debuggen. Beide werfen ein AttributeError
auf jedes Attribut.
Komplettes Arbeitsbeispiel: https://gist.github.com/mxplusb/8f487a6ff3c781689799bb7ce1dec3f3. Es entfernt das Audio aus einer Videodatei mit ffmpeg
im richtigen Format, lädt es in GCS und führt dann eine asynchrone Spracherkennung durch. Ich versuche alle Transkripte in eine große Textzeichenfolge zu verketten.
Also das war es, es war ein Tippfehler! Ich musste ein wenig mehr Debugging machen, aber das ist das Wesentliche, danke! – mxplusb