首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我试图将Google文本中的声音合成成语音API时出错了

我试图将Google文本中的声音合成成语音API时出错了
EN

Stack Overflow用户
提问于 2018-09-14 17:45:47
回答 1查看 348关注 0票数 2

我不知道为什么在响应下面的代码时会出现这个错误。

代码语言:javascript
运行
复制
# 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的死区)

EN

回答 1

Stack Overflow用户

发布于 2018-09-14 20:26:10

您是否为项目启用了文本到语音API?或者,如果您只是在本地运行它,您是否设置了应用程序默认凭据?您可能没有正确的权限,并且对文本到语音API的请求正在超时。

我能够在App上完成以下工作:

app.yaml

代码语言:javascript
运行
复制
runtime: python37

requirements.txt

代码语言:javascript
运行
复制
flask
google-cloud-texttospeech

main.py

代码语言:javascript
运行
复制
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')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52336941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档