首页 > 解决方案 > ImportError:无法导入名称“枚举”

问题描述

我正在尝试使用 Google Speech API 实时识别来自麦克风输入的语音。我试过https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/speech/cloud-client/transcribe_streaming_mic.py 了,但出现了这个错误。有谁知道如何解决这个问题?

from google.cloud.speech import enums
ImportError: cannot import name 'enums'

更新: 我已经按照官方 Cloud Speech API 网站的建议通过在虚拟环境中运行代码解决了这个问题。但是,我仍然不明白为什么我们需要在虚拟环境而不是我的原始环境中运行它,因为虚拟环境不是 Linux 或其他操作系统。

标签: pythonspeech-recognitionspeech-to-textgoogle-speech-api

解决方案


使用pip install google.cloud.speech,您将获得最新版本,当前为V2

V2中,枚举类型已被删除并且不再需要。

https://github.com/googleapis/python-speech/blob/master/UPGRADING.md#enums-and-types


推荐阅读