【问题标题】:ImportError: cannot import name 'enums'ImportError:无法导入名称“枚举”
【发布时间】:2018-11-28 02:54:19
【问题描述】:

我正在尝试使用 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 或其他操作系统。

【问题讨论】:

  • 似乎是一个愚蠢的问题,但您是否先安装了 google-cloud-speech?
  • 是的,我安装了它。
  • 我已经尝试过了,它适用于 virtualenv 和正常。您是否不小心安装了 python3 并使用另一个 python 运行? (也许你有双重安装。)@sttc1998

标签: python speech-recognition speech-to-text google-speech-api


【解决方案1】:

我正在使用云功能将音频转录为文本。 我相信 google-cloud-speech 的文档已经更新,您可以参考文档。 https://pypi.org/project/google-cloud-speech/。我相信这个类现在叫做speech_v1,你可以使用别名“as speech”来使github示例代码工作。

from google.cloud import speech_v1 as speech
from google.cloud.speech_v1 import enums
from google.cloud.speech_v1 import types

HTH。

【讨论】:

    【解决方案2】:

    我的工作是使用以下导入

    from google.cloud.speech_v1.gapic import enums
    

    【讨论】:

      【解决方案3】:

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

      V2 中,enumstypes 已被移除且不再需要。

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

      【讨论】:

        猜你喜欢
        • 2020-01-04
        • 1970-01-01
        • 2016-03-31
        • 2014-10-10
        • 2014-09-20
        • 2014-08-28
        • 2014-06-10
        • 2016-05-16
        • 2019-05-25
        相关资源
        最近更新 更多