【问题标题】:How to fix ' missing google-api-python-client'? Using Python, Jupyter Notebook and SpeechRecognition如何修复“缺少 google-api-python-client”?使用 Python、Jupyter Notebook 和 SpeechRecognition
【发布时间】:2024-01-21 02:35:01
【问题描述】:

我正在尝试对使用 python 3.x、jupyter notebook 和 SpeechRecognition 库的一些音频文件执行语音识别,但我得到:

'RequestError: missing google-api-python-client module: ensure that google-api-python-client is set up correctly.'

在使用识别谷歌云时,即使我已经安装它并在运行时看到“google-api-python-client”

conda list

使用默认的 google 语音 API 密钥时一切顺利。

使用的代码如下:

import speech_recognition as sr

r = sr.Recognizer()

with open('file_with_keys.json') as f:
GOOGLE_CLOUD_SPEECH_CREDENTIALS = f.read()

test_audio = sr.AudioFile('audio_file.wav')
with test_audio as source:
    audio = r.record(source)

r.recognize_google_cloud(audio, language = 'es-MX', 
credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS)

预期结果包括我当前文件的转录。

非常感谢。

【问题讨论】:

标签: python jupyter-notebook speech-recognition google-cloud-speech


【解决方案1】:

你能公开分享这个笔记本吗?您是否在控制台而不是笔记本中尝试过此操作,如果这样做会产生什么结果?

另外,当你说

“使用默认的 google 语音 API 密钥时一切顺利。”

您能否更具体地说明这意味着什么或它与问题的关系?您没有收到 API 密钥错误。

对我来说,只有在虚拟环境中运行才能让我的 python 代码正常工作。你的笔记本有这种情况吗?

见:https://cloud.google.com/python/setup 还有:https://anbasile.github.io/programming/2017/06/25/jupyter-venv/

【讨论】: