Код: Выделить всё
def speak(text, language):
client = texttospeech.TextToSpeechClient()
synthesis_input = texttospeech.SynthesisInput(text=text)
voice = texttospeech.VoiceSelectionParams(
language_code=language,
ssml_gender=texttospeech.SsmlVoiceGender.NEUTRAL
)
audio_config = texttospeech.AudioConfig(
audio_encoding=texttospeech.AudioEncoding.MP3
)
response = client.synthesize_speech(input=synthesis_input, voice=voice,
audio_config=audio_config)
audio = pyaudio.PyAudio()
stream = audio.open(format=pyaudio.paInt16,
channels=1,
rate=16000,
output=True)
audio_stream = io.BytesIO(response.audio_content)
chunk = 1024
data = audio_stream.read(chunk)
while data:
stream.write(data)
data = audio_stream.read(chunk)
stream.stop_stream()
stream.close()
audio.terminate()
speak("Hello! Did you see that?", "en-US")
Благодарю всех, кто пытается помочь. Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/793 ... ng-pyaudio