Use Google Text-to-Speech

For a project idea I want to see the quality of Google TTS as a reader of a longer story.

Again the most complicated thing is getting the correct key-file to be allowed to call the API. Thankfully the quickstart-guide helps here:

# replace YOUR_PROJECT with the correct value for your project

# create a service account named "tts-quickstart"
gcloud iam service-accounts create tts-quickstart --project YOUR_PROJECT

# give the new user the right "roles/viewer"
gcloud projects add-iam-policy-binding YOUR_PROJECT --member \ \
  --role roles/viewer

# export the key as json file
gcloud iam service-accounts keys create tts-key.json \

# and now set it in the environment for the script below to actually use it

Next the actual Python code that uses the API to generate an mp3 file for a given text.

from import texttospeech_v1beta1 as tts

client = tts.TextToSpeechClient()

request = tts.SynthesizeSpeechRequest(
        text="There was a stream at the foot of the hill. "
        "They filled their bottles and the small camping "
        "kettle at a little fall where the water fell a few "
        "feet over an outcrop of grey stone. "
        "It was icy cold; and they spluttered and puffed "
        "as they bathed their faces and hands."
        language_code="en-GB", name="en-GB-Neural2-D"

response = client.synthesize_speech(request=request)
with open("output.mp3", "wb") as fp:

I selected the voice en-GB-Neural2-D on the demo website of Google TTS. The quality seems good enough for my usecase.