我是Google语音识别API的新用户。 每次我使用它,我总是有这个错误
Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/speech_recognition/__init__.py", line 930, in recognize_google_cloud
response = request.execute() File "/usr/local/lib/python3.5/dist-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs) File "/usr/local/lib/python3.5/dist-packages/googleapiclient/http.py", line 840, in execute
raise HttpError(resp, content, uri=self.uri) googleapiclient.errors.HttpError: <HttpError 400 when requesting https://speech.googleapis.com/v1/speech:recognize?alt=json returned "RecognitionAudio not set.">
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "pakgne_speech_recognition.py", line 62, in <module>
text = r.recognize_google_cloud(audio, language="fr-FR", credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS) File "/usr/local/lib/python3.5/dist-packages/speech_recognition/__init__.py", line 932, in recognize_google_cloud
raise RequestError(e) speech_recognition.RequestError: <HttpError 400 when requesting https://speech.googleapis.com/v1/speech:recognize?alt=json returned "RecognitionAudio not set.">
这是我的python3代码
with open("api-key.json") as api:
GOOGLE_CLOUD_SPEECH_CREDENTIALS = api.read()
for wav_file in files:
duration = get_duration_wav(wav_file)
print(wav_file)
with sr.AudioFile(wav_file) as source:
for off in range(0, duration, 60):
audio = r.record(source, offset=off, duration=60)
text = r.recognize_google_cloud(audio, language="fr-FR", credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS)
print("{} - {}".format(off, text))
print("\n")
请问如何解决?