ModuleNotFoundError: нет модуля с именем google.cloud - PullRequest
0 голосов
/ 23 февраля 2019

Я использую API "облако в речь", и у меня возникла общая проблема: модуль не найден.Я пробовал решения, которые есть у большинства людей, единственная проблема в том, что я использую Windows, и большинство решений для Mac или Linux (хотя это не должно быть такой большой проблемой).

Я запустил'список пипсов' в командной строке и вот что он вернул:

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

И если это помогает, это то, что я выполняю в операторе импорта ( это также взято из Googleучебник )

>> from google.cloud import texttospeech

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

Есть решения?

1 Ответ

0 голосов
/ 23 февраля 2019

ModuleNotFoundError: Нет модуля с именем google.cloud

Чтобы решить эту проблему:

  1. Удалите облако Google: pip uninstall google-cloud
  2. Переустановите с обновлением google-cloud-texttospeech: pip install --upgrade google-cloud-textdtospeech

Библиотека google-cloud устарела.Не устанавливайте эту библиотеку и не используйте ее.

Пример кода для начала работы с 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"')
...