Python I';我在谷歌合成语音时出错了';s文本语音转换API
我不知道为什么在响应以下代码时会出现此错误Python I';我在谷歌合成语音时出错了';s文本语音转换API,python,google-app-engine,google-cloud-platform,text-to-speech,Python,Google App Engine,Google Cloud Platform,Text To Speech,我不知道为什么在响应以下代码时会出现此错误 # 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"]=
# 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的u'截止日期'
是否为项目启用了文本到语音API?或者,如果您只是在本地运行,是否设置了应用程序默认凭据?可能是您没有正确的权限,对文本到语音API的请求正在超时 我能够在App Engine上实现以下功能: 在
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')
请将错误以文本形式而不是图像形式发布好的,我认为图片会更好。将错误以文本形式发布,以便其他用户可以复制它是一种很好的做法。这也提高了可读性。非常好,非常有意义,谢谢!您还有其他例外吗?似乎缺少部分。令人惊讶的是,API工作得非常完美我没有对代码进行任何更改。是的,服务已启用,凭据已设置。您能否在问题中包含更多关于如何使用API的代码?