问题
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
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'
Any solutions?
回答1:
ModuleNotFoundError: No module named 'google.cloud'
To solve this problem:
- Remove google-cloud:
pip uninstall google-cloud
- Reinstall with update google-cloud-texttospeech:
pip install --upgrade google-cloud-textdtospeech
The library google-cloud is deprecated. Do no 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"')
来源:https://stackoverflow.com/questions/54836399/modulenotfounderror-no-module-named-google-cloud