我正在尝试将google api与python的speech_recognition库一起使用,但调试后会返回解码错误。
Traceback (most recent call last):
File "[...]Google Text To Speech.py", line 22, in <module>
r.recognize_google(audio)
File "[...]\Python\Python37\lib\site-packages\speech_recognition\__init__.py", line 845, in recognize_google
response_text = response.read().decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
并且当尝试使用麦克风设备识别时,回溯也相同。
是因为Google api和其他所有API(例如IBM和Bing)一样重新查询了一个键,还是我很笨?
代码:
import speech_recognition as sr
r = sr.Recognizer()
voice = sr.AudioFile('maybe-next-time.wav')
with voice as source:
audio = r.record(source, duration=4)
r.recognize_google(audio)
这就是没有解码utf8“ print(response.read())”的“ 859行”的打印:
b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xaaV*J-.\xcd)Q\xb2\x8a\x8e\xad\xe5\x02\x00\x00\x00\xff\xff\x03\x00\xf2\x0c\xcc\xd5\x0e\x00\x00\x00'