Как проверить Google Cloud Speech на текст с помощью python? - PullRequest
0 голосов
/ 06 ноября 2019

Попытка проверить Google Cloud Speech на текст с использованием python и продолжить работу с той же ошибкой не может найти решение в Интернете.

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]
...