Google text-to-speech API Pitch Adjustment

Viewed 514

How can I adjust the pitch to -1.20 in this code:

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

The Google Text-to-Speech documentation is not pretty clear on this. According to the documentation the 'pitch' can be adjusted in the range [-20.0, 20.0], but where can this parameter be adjusted.

1 Answers
audio_config = texttospeech.AudioConfig(pitch=-1.20, audio_encoding=texttospeech.AudioEncoding.LINEAR16)
Related