【问题标题】:I'm getting error while trying to synthesize voice in Google's text to speech API尝试在 Google 的文本转语音 API 中合成语音时出错
【发布时间】:2018-09-14 17:45:47
【问题描述】:

我不知道为什么在响应以下代码时收到此错误。

# 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(u'Deadline of 600.0s exceeded while calling '

【问题讨论】:

  • 请将错误发布为文本而不是图像
  • 好的,我觉得有图片会更好。
  • 最好将错误以文本形式发布,以便其他用户可以复制。它还增加了可读性。
  • 很好,很有道理,谢谢!
  • 您的例外还有更多吗?好像缺少一部分。

标签: python google-app-engine google-cloud-platform text-to-speech


【解决方案1】:

您是否为您的项目启用了 Text-To-Speech API?或者,如果您只是在本地运行它,您是否设置了应用程序默认凭据?您可能没有正确的权限并且对 Text-To-Speech 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 的代码?
猜你喜欢
  • 1970-01-01
  • 2014-07-25
  • 2023-03-03
  • 1970-01-01
  • 2020-04-26
  • 2012-09-29
  • 2018-03-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多