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}"')