Я использую API-интерфейс преобразования текста в речь в облаке Google. Иногда он работает, но иногда не работает. В чем может быть проблема, так как я не могу понять. Я использую Linux.
Ниже приведен мой код. Он иногда выполняется и дает результат, а иногда он просто не дает никакого звука.
def synthesize_text (text):
"" "Синтезирует речь из входной строки текста." ""
из google.cloud импортировать текстовую речь
импорт VLC
client = texttospeech.TextToSpeechClient ()
input_text = texttospeech.types.SynthesisInput(text=text)
# Note: the voice can also be specified by name.
# Names of voices can be retrieved with client.list_voices().
voice = texttospeech.types.VoiceSelectionParams(
language_code='en-US',
ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE)
audio_config = texttospeech.types.AudioConfig(
audio_encoding=texttospeech.enums.AudioEncoding.MP3)
response = client.synthesize_speech(input_text, voice, audio_config)
#return response.audio_content
# The response's audio_content is binary.
with open('output.mp3', 'wb') as out:
out.write(response.audio_content)
print('Audio content written to file "output.mp3"')
vlc_ins=vlc.MediaPlayer('output.mp3')
vlc_ins.play()