1

I'm a beginner in coding. I am using the Google Cloud Text to Speech API for Python on a small program I'm using. The function is working and I get the synthesized voice results, but the MP3 file is different from what I need. I chose 'en-GB-Wavenet-C'(British accent female voice) as language_code, but the MP3 file sounds American accent male voice.

I visited Cloud Text to Speech API website(https://cloud.google.com/text-to-speech/) and tried "Speak it" demo. I tried 'en-GB-Wavenet-C' and it sounded British accent female voice.

I would like to know the appropriate code so that I get 'en-GB-Wavenet-C' voice result.

I use Debian 9.3 from Windows Subsystem for Linux.

I use Google Cloud SDK 210.0.0.

Thank you in advance.

Sincerely, Kazu

This is my code:

#!/usr/bin/env python

from google.cloud import texttospeech
client = texttospeech.TextToSpeechClient()

with open('resources/hello.ssml', 'r') as f:
    ssml = f.read()
    input_text = texttospeech.types.SynthesisInput(ssml=ssml)

# Note: the voice can also be specified by name.
# Names of voices can be retrieved with client.list_voices().
voice = texttospeech.types.VoiceSelectionParams(language_code='en-GB-Wavenet-C')

audio_config = texttospeech.types.AudioConfig(
    audio_encoding=texttospeech.enums.AudioEncoding.MP3)

response = client.synthesize_speech(input_text, voice, audio_config)

# The response's audio_content is binary.
with open('output.mp3', 'wb') as out:
    out.write(response.audio_content)
    print('Audio content written to file "output.mp3"')
# [END tts_synthesize_ssml_file]
Kazuaki Suzuki
  • 1,025
  • 6
  • 19
  • 33

1 Answers1

2
 voice = texttospeech.types.VoiceSelectionParams(language_code='en-GB-Wavenet-C')

Should be

 voice = texttospeech.types.VoiceSelectionParams(language_code='en-GB', name="en-GB-Wavenet-C")
Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
  • Thank you very much for your quick help. I tried your suggestion. However it didn't solve my problem. This Error message appeared. – Kazuaki Suzuki Jan 13 '19 at 22:33
  • Traceback (most recent call last): File "synthe_file_GB.py", line 17, in response = client.synthesize_speech(input_text, voice, audio_config) File "/mnt/c/gcp/voice/.venv/local/lib/python2.7/site-packages/google/cloud/texttospeech_v1/gapic/text_to_speech_client.py", line 257, in synthesize_speech request, retry=retry, timeout=timeout, metadata=metadata) File "/mnt/c/gcp/voice/.venv/local/lib/python2.7/site-packages/google/api_core/gapic_v1/method.py", line 143, in __call__ return wrapped_func(*args, **kwargs) – Kazuaki Suzuki Jan 13 '19 at 22:36
  • File "/mnt/c/gcp/voice/.venv/local/lib/python2.7/site-packages/google/api_core/retry.py", line 270, in retry_wrapped_func on_error=on_error, File "/mnt/c/gcp/voice/.venv/local/lib/python2.7/site-packages/google/api_core/retry.py", line 179, in retry_target return target() File "/mnt/c/gcp/voice/.venv/local/lib/python2.7/site-packages/google/api_core/timeout.py", line 214, in func_with_timeout return func(*args, **kwargs) – Kazuaki Suzuki Jan 13 '19 at 22:37
  • File "/mnt/c/gcp/voice/.venv/local/lib/python2.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 "/mnt/c/gcp/voice/.venv/local/lib/python2.7/site-packages/six.py", line 737, in raise_from raise value google.api_core.exceptions.InvalidArgument: 400 Could not find TTS server to handle request for application_id: 'cloud-tts' and trigger_application_id: '' and voice_request: language: "en-gb" name: "cloud-Wavenet-C" – Kazuaki Suzuki Jan 13 '19 at 22:37
  • Cloud you please help me? – Kazuaki Suzuki Jan 13 '19 at 22:38
  • Try name="en-GB-Wavenet-C" – Nikolay Shmyrev Jan 14 '19 at 09:37
  • I got it! The answer is [language_code='en-GB', name="en-GB-Wavenet-C"]. Thank you very much for your help!!! – Kazuaki Suzuki Jan 15 '19 at 10:40