ModuleNotFoundError:没有名为"google.cloud"的模块 [英] ModuleNotFoundError: No module named 'google.cloud'

查看:270
本文介绍了ModuleNotFoundError:没有名为"google.cloud"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用Google的云文字语音转换" API,但遇到的常见问题是找不到该模块.我已经尝试了大多数人拥有的解决方案,唯一的问题是我使用Windows,并且大多数解决方案都适用于Mac或Linux(尽管这不应该是一个大问题).

I'm looking to use the Google "cloud text to speech" api, and I'm having the common problem of the module not being found. I've tried the solutions that most people have, only problem being that I use windows and most of the solutions are for mac or Linux (although this shouldn't be that big of an issue).

我在命令行上运行了点列表",这是它返回的内容:

I ran the 'pip list' on the command line and here's what it returned:

google                    2.0.1
google-api-core           1.7.0
google-auth               1.6.3
google-cloud              0.34.0
google-cloud-texttospeech 0.4.0
googleapis-common-protos  1.5.8

如果有帮助,这就是我在import语句上运行的内容(这也取自Google的教程)

And if this helps, this is what I have been running on the import statement (this is also taken from google's tutorial)

>> from google.cloud import texttospeech

from google.cloud import texttospeech
ModuleNotFoundError: No module named 'google.cloud'

有解决方案吗?

推荐答案

ModuleNotFoundError:没有名为"google.cloud"的模块

ModuleNotFoundError: No module named 'google.cloud'

要解决此问题:

  1. 删除google-cloud:pip uninstall google-cloud
  2. 使用更新google-cloud-texttospeech重新安装:pip install --upgrade google-cloud-texttospeech
  1. Remove google-cloud: pip uninstall google-cloud
  2. Reinstall with update google-cloud-texttospeech: pip install --upgrade google-cloud-texttospeech

不推荐使用库google-cloud.不要安装或使用此库.

The library google-cloud is deprecated. Do not install this library or use it.

示例代码可帮助您开始使用文本到语音:

Example code to get you started with Text to Speech:

from google.cloud import texttospeech

# Instantiates a client
client = texttospeech.TextToSpeechClient()

# Set the text input to be synthesized
synthesis_input = texttospeech.types.SynthesisInput(text="Hello, World!")

# Build the voice request, select the language code ("en-US") and the ssml
# voice gender ("neutral")
voice = texttospeech.types.VoiceSelectionParams(
    language_code='en-US',
    ssml_gender=texttospeech.enums.SsmlVoiceGender.NEUTRAL)

# Select the type of audio file you want returned
audio_config = texttospeech.types.AudioConfig(
    audio_encoding=texttospeech.enums.AudioEncoding.MP3)

# Perform the text-to-speech request on the text input with the selected
# voice parameters and audio file type
response = client.synthesize_speech(synthesis_input, voice, audio_config)

# The response's audio_content is binary.
with open('output.mp3', 'wb') as out:
    # Write the response to the output file.
    out.write(response.audio_content)
    print('Audio content written to file "output.mp3"')

这篇关于ModuleNotFoundError:没有名为"google.cloud"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆