尝试使用python测试Google Cloud Speech到文本的文本,并继续遇到相同的错误,无法在线找到解决方案。
import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
# recognize speech using Google Cloud Speech
GOOGLE_CLOUD_SPEECH_CREDENTIALS = r'GOOGLE_CLOUD_SPEECH_CREDENTIALS_go_here'
try:
print("Google Cloud Speech thinks you said " + r.recognize_google_cloud(audio, credentials_json = GOOGLE_CLOUD_SPEECH_CREDENTIALS))
except sr.UnknownValueError:
print("Google Cloud Speech could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Cloud Speech service; {0}".format(e))
这是我不断得到的错误:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\speech_recognition\__init__.py", line 885, in recognize_google_cloud
try: json.loads(credentials_json)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
在处理上述异常期间,发生了另一个异常:
Traceback (most recent call last):
File "C:\Users\User\Desktop\work\testing3.py", line 12, in <module>
print("Google Cloud Speech thinks you said " + r.recognize_google_cloud(audio, credentials_json = GOOGLE_CLOUD_SPEECH_CREDENTIALS))
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\speech_recognition\__init__.py", line 886, in recognize_google_cloud
except Exception: raise AssertionError("``credentials_json`` must be ``None`` or a valid JSON string")
AssertionError: ``credentials_json`` must be ``None`` or a valid JSON string
[enter image description here][1]