我不知道为什么在响应下面的代码时会出现这个错误。
# imports
from google.cloud import texttospeech_v1beta1 as texttospeech
AUDIO_PROCESS_ROOT = 'path_audio'
VEL_NORMAL = 1.0
KEY_API_ROOT = 'path_key'
# set credentials environment
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]=KEY_API_ROOT+"nome.json"
def TextToSpeech(text):
client = texttospeech.TextToSpeechClient()
input_text = texttospeech.types.SynthesisInput(text=text)
voice = texttospeech.types.VoiceSelectionParams(language_code='en-US', name='en-US-Wavenet- B',ssml_gender=texttospeech.enums.SsmlVoiceGender.MALE)
#speaking_rate --> responsavel pela taxa de velocidade no intervalo de [0.25 a 4.0], sendo 1.0 a velocidade normal padrão
audio_config = texttospeech.types.AudioConfig(audio_encoding=texttospeech.enums.AudioEnc oding.MP3, speaking_rate=VEL_NORMAL)
response = client.synthesize_speech(input_text, voice,audio_config)
with open(AUDIO_PROCESS_ROOT+'audio_normal.mp3', 'wb') as out:
out.write(response.audio_content)
TextToSpeech("Hi, how are you")
错误:
RetryError(在呼叫时超过了600.0s的死区)
发布于 2018-09-14 20:26:10
您是否为项目启用了文本到语音API?或者,如果您只是在本地运行它,您是否设置了应用程序默认凭据?您可能没有正确的权限,并且对文本到语音API的请求正在超时。
我能够在App上完成以下工作:
在app.yaml
中
runtime: python37
在requirements.txt
中
flask
google-cloud-texttospeech
在main.py
中
from flask import Flask, Response
from google.cloud import texttospeech
app = Flask(__name__)
@app.route("/")
def hello():
client = texttospeech.TextToSpeechClient()
input_text = texttospeech.types.SynthesisInput(text="Hi, what's up")
voice = texttospeech.types.VoiceSelectionParams(
language_code="en-US",
ssml_gender=texttospeech.enums.SsmlVoiceGender.MALE,
)
audio_config = texttospeech.types.AudioConfig(
audio_encoding=texttospeech.enums.AudioEncoding.MP3
)
response = client.synthesize_speech(input_text, voice, audio_config)
return Response(response.audio_content, mimetype='audio/mp3')
https://stackoverflow.com/questions/52336941
复制相似问题