试图输出中文。
google.api_core.exceptions.InvalidArgument:400找不到TTS服务器来处理application_id:“ cloud-tts”和trigger_application_id:”和voice_request:语言:“ cmn-tw”的请求
在“ en-US”下可以正常工作,但在“ cmn-tw”上不能工作
遵循Google Text-to-Speech API Client Libraries的示例代码
以下是我的代码。
#!/usr/bin/python
#coding:utf-8
"""Synthesizes speech from the input string of text or ssml.
Note: ssml must be well-formed according to:
https://www.w3.org/TR/speech-synthesis/
"""
from google.cloud import texttospeech
# Instantiates a client
client = texttospeech.TextToSpeechClient()
mytext = "這是一個測試"
# Set the text input to be synthesized
synthesis_input = texttospeech.types.SynthesisInput(text=mytext)
# Build the voice request, select the language code ("en-US") and the ssml
# voice gender ("neutral")
voice = texttospeech.types.VoiceSelectionParams(
language_code='cmn-tw',
ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE)
# Select the type of audio file you want returned
audio_config = texttospeech.types.AudioConfig(
audio_encoding=texttospeech.enums.AudioEncoding.MP3)
# 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)
# The response's audio_content is binary.
with open('output.mp3', 'wb') as out:
# Write the response to the output file.
out.write(response.audio_content)
print('Audio content written to file "output.mp3"')