我已经在我的应用程序中启动并运行了Google Text to Speech。大多数情况下,API工作得很好,我收到的音频文件响应播放得很好。
但有时我会收到以下错误:
Google::Cloud::InternalError (13:Internal error encountered.):我有安全措施来防止我的应用程序遇到使用配额,所以我不认为是这样的。此外,在我实施这些保护措施之前,如果我确实超出了配额,错误消息会显示您超出了配额。
有人知道这条消息是什么意思吗?
或者,如果有人知道一个优雅地处理此错误的好方法(这是一个Rails应用程序)。
谢谢
发布于 2020-05-25 21:15:20
好的,除了一些内部错误,我不知道谷歌到底出了什么问题。然而,我确实想出了一个解决方案来挽救这个错误,并允许我继续我的文本到语音的工作。
以下是我的代码对于感兴趣的人的样子:
def convert_to_audio(text, gender)
client = Google::Cloud::TextToSpeech.text_to_speech
input_text = { text: text }
# Note: the voice can also be specified by name.
# Names of voices can be retrieved with client.list_voices
# https://cloud.google.com/text-to-speech/docs/voices
if gender == 'MALE'
name = 'en-US-Standard-D'
else
name = 'en-US-Standard-E'
end
voice = {
language_code: "en-US",
name: name,
ssml_gender: gender
}
audio_config = { audio_encoding: "MP3" }
begin
retries ||= 0
response = client.synthesize_speech(
input: input_text,
voice: voice,
audio_config: audio_config
)
rescue Google::Cloud::InternalError
puts "The Google error occurred"
retry if (retries += 1) < 3
end基本上现在,当我从Google得到这个错误时,我会重试合成语音呼叫。
Google在这个API上设置了非常严格的配额,我猜这是因为更大更频繁的请求倾向于更频繁地抛出错误,所以他们试图进行质量控制。
我也为那些感兴趣的人找到了这个错误映射:
namespace error {
// These values must match error codes defined in google/rpc/code.proto.
enum Code {
OK = 0,
CANCELLED = 1,
UNKNOWN = 2,
INVALID_ARGUMENT = 3,
DEADLINE_EXCEEDED = 4,
NOT_FOUND = 5,
ALREADY_EXISTS = 6,
PERMISSION_DENIED = 7,
UNAUTHENTICATED = 16,
RESOURCE_EXHAUSTED = 8,
FAILED_PRECONDITION = 9,
ABORTED = 10,
OUT_OF_RANGE = 11,
UNIMPLEMENTED = 12,
INTERNAL = 13,
UNAVAILABLE = 14,
DATA_LOSS = 15,
};
} // namespace errorhttps://stackoverflow.com/questions/62000323
复制相似问题