Simple questions

40 views
Skip to first unread message

Jonny Natali

unread,
Feb 15, 2021, 12:58:11 PM2/15/21
to gce-discussion
Hello,
I don't know how to code so this is probably a hyper stupid question.

Im trying to run the text to speech api.
I'm trying to change the name of the files I save to .wav but pyton only gives error messages.
I tried to change the filename=...... with
filename=f"{one}.wav" 

but didnt succed, is some one kind enough to tell me how to fix this?

thanks

This is the script:

from google.cloud import texttospeech


def text_to_wav(voice_name, text):
    language_code = "-".join(voice_name.split("-")[:2])
    text_input = texttospeech.SynthesisInput(text=text)
    voice_params = texttospeech.VoiceSelectionParams(
        language_code=language_code, name=voice_name
    )
    audio_config = texttospeech.AudioConfig(
        audio_encoding=texttospeech.AudioEncoding.LINEAR16
    )

    client = texttospeech.TextToSpeechClient()
    response = client.synthesize_speech(
        input=text_input, voice=voice_params, audio_config=audio_config
    )

    filename = f"{language_code}.wav"
    with open(filename, "wb") as out:
        out.write(response.audio_content)
        print(f'Audio content written to "{filename}"')

Jinjun (Cloud Platform Support)

unread,
Feb 16, 2021, 8:05:11 PM2/16/21
to gce-discussion
Hello,

Your question is not directly related to text-to-speech API. For Python programming questions, you can post on Stackoverflow.com.

Sean Natali

unread,
Feb 17, 2021, 9:55:13 AM2/17/21
to Jinjun (Cloud Platform Support), gce-discussion
Thanks

--
© 2018 Google Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043
 
Email preferences: You received this email because you signed up for the Google Compute Engine Discussion Google Group (gce-dis...@googlegroups.com) to participate in discussions with other members of the Google Compute Engine community and the Google Compute Engine Team.
---
You received this message because you are subscribed to a topic in the Google Groups "gce-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gce-discussion/cvwzwAiF7Vw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gce-discussio...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gce-discussion/4f48b21e-233f-49c4-8362-0e58cf6409c4n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages