I get an error when trying to synthesize speech over ~1500 characters (4MiB) despite documentation stating the limit is 5000 characters. There is no problem synthesizing 5000 characters when using MP3 encoding (output file size: 1.2MB) on the same text, indicating that the problem is definitely just the larger file size when using LINEAR16 encoding (output file size: >13MB). This seems to be related to issues googleapis/google-cloud-python#5819, googleapis/google-cloud-python#5574
from google.cloud import texttospeech
import os
from tqdm import tqdm
import numpy as np
CORPUS = 'MothClean'
GENDER = 'Male1'
voice_name = 'en-US-Wavenet-D'
pitch = 0
dirname = 'Text/'+CORPUS+'/'
outdirname = 'Speech/'+CORPUS+'/'+GENDER+'/'
# Instantiates a client
client = texttospeech.TextToSpeechClient()
langCode = voice_name[:5]
# Build the voice request, select the language code
voice = texttospeech.types.VoiceSelectionParams(language_code=langCode,name=voice_name)
# Select the type of audio file you want returned
audio_config = texttospeech.types.AudioConfig(
audio_encoding = texttospeech.enums.AudioEncoding.LINEAR16,
speaking_rate = 1,
pitch = pitch)
# Get items in directory with text files here
items = os.listdir(dirname)
filelist = sorted([fn for fn in items if '.txt' in fn])
# Iterate through text files, performing TTS and saving audio as we go
for file in tqdm(filelist):
with open(dirname+file, 'r') as text_file:
text = text_file.read()
text = text[:3000]
# Set the text input to be synthesized
synthesis_input = texttospeech.types.SynthesisInput(text=text)
# Perform the text-to-speech request on the text input with the selected
# voice parameters and audio file type
response = client.synthesize_speech(synthesis_input, voice, audio_config)
name = file[0:-4]
with open(outdirname+name+'.wav', 'wb') as out:
# Write the response to the output file.
out.write(response.audio_content)
Traceback (most recent call last):
File "/Users/vinayraghavan/anaconda3/envs/aad/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
return callable_(*args, **kwargs)
File "/Users/vinayraghavan/anaconda3/envs/aad/lib/python3.7/site-packages/grpc/_channel.py", line 550, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "/Users/vinayraghavan/anaconda3/envs/aad/lib/python3.7/site-packages/grpc/_channel.py", line 467, in _end_unary_response_blocking
raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
status = StatusCode.RESOURCE_EXHAUSTED
details = "Received message larger than max (8351413 vs. 4194304)"
debug_error_string = "{"created":"@1581435404.899284000","description":"Received message larger than max (8351413 vs. 4194304)","file":"src/core/ext/filters/message_size/message_size_filter.cc","file_line":174,"grpc_status":8}"
>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "gcloud_tts.py", line 92, in <module>
response = client.synthesize_speech(synthesis_input, voice, audio_config)
File "/Users/vinayraghavan/anaconda3/envs/aad/lib/python3.7/site-packages/google/cloud/texttospeech_v1/gapic/text_to_speech_client.py", line 322, in synthesize_speech
request, retry=retry, timeout=timeout, metadata=metadata
File "/Users/vinayraghavan/anaconda3/envs/aad/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py", line 143, in __call__
return wrapped_func(*args, **kwargs)
File "/Users/vinayraghavan/anaconda3/envs/aad/lib/python3.7/site-packages/google/api_core/retry.py", line 273, in retry_wrapped_func
on_error=on_error,
File "/Users/vinayraghavan/anaconda3/envs/aad/lib/python3.7/site-packages/google/api_core/retry.py", line 182, in retry_target
return target()
File "/Users/vinayraghavan/anaconda3/envs/aad/lib/python3.7/site-packages/google/api_core/timeout.py", line 214, in func_with_timeout
return func(*args, **kwargs)
File "/Users/vinayraghavan/anaconda3/envs/aad/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.ResourceExhausted: 429 Received message larger than max (8351413 vs. 4194304)
I get an error when trying to synthesize speech over ~1500 characters (4MiB) despite documentation stating the limit is 5000 characters. There is no problem synthesizing 5000 characters when using MP3 encoding (output file size: 1.2MB) on the same text, indicating that the problem is definitely just the larger file size when using LINEAR16 encoding (output file size: >13MB). This seems to be related to issues googleapis/google-cloud-python#5819, googleapis/google-cloud-python#5574
Environment details
API:
OS:
Python version:
Google Cloud Service Info:
Steps to reproduce
Code example
Stack trace