Google语音测试无法正常工作,错误:google.api_core.exceptions.DeadlineExceeded:超过504个截止日期

时间:2020-03-01 08:16:42

标签: python google-api-python-client

我尝试使用python 3.7在我的window 10计算机上的Google TTS中运行一个示例,但是它不起作用。我已经将每一步设置为官方页面https://cloud.google.com/text-to-speech/docs/quickstart-client-libraries,但是当我将python文件作为页面中的示例运行时,它失败了。

示例代码如下:文件名:ggtts.py

"""Synthesizes speech from the input string of text or ssml.

Note: ssml must be well-formed according to:
    https://www.w3.org/TR/speech-synthesis/
"""
from google.cloud import texttospeech

# Instantiates a client
client = texttospeech.TextToSpeechClient()

# Set the text input to be synthesized
synthesis_input = texttospeech.types.SynthesisInput(text="Hello, World!")

# Build the voice request, select the language code ("en-US") and the ssml
# voice gender ("neutral")
voice = texttospeech.types.VoiceSelectionParams(
    language_code='en-US',
    ssml_gender=texttospeech.enums.SsmlVoiceGender.NEUTRAL)

# Select the type of audio file you want returned
audio_config = texttospeech.types.AudioConfig(
    audio_encoding=texttospeech.enums.AudioEncoding.MP3)

# Perform the text-to-speech request on the text input with the selected
# voice parameters and audio file type
response = client.synthesize_speech(synthesis_input, voice, audio_config)

# The response's audio_content is binary.
with open('output.mp3', 'wb') as out:
    # Write the response to the output file.
    out.write(response.audio_content)
    print('Audio content written to file "output.mp3"')

以下错误:

Traceback (most recent call last):
  File "D:\Program Files\Python\Python37\lib\site-packages\google\api_core\grpc_helpers.py", line 57, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "D:\Program Files\Python\Python37\lib\site-packages\grpc\_channel.py", line 826, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "D:\Program Files\Python\Python37\lib\site-packages\grpc\_channel.py", line 729, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.DEADLINE_EXCEEDED
    details = "Deadline Exceeded"
    debug_error_string = "{"created":"@1583048623.437000000","description":"Deadline Exceeded","file":"src/core/ext/filters/deadline/deadline_filter.cc","file_line":69,"grpc_status":4}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\files\mypyfile\ggtts.py", line 26, in <module>
    response = client.synthesize_speech(synthesis_input, voice, audio_config)
  File "D:\Program Files\Python\Python37\lib\site-packages\google\cloud\texttospeech_v1\gapic\text_to_speech_client.py", line 322, in synthesize_speech
    request, retry=retry, timeout=timeout, metadata=metadata
  File "D:\Program Files\Python\Python37\lib\site-packages\google\api_core\gapic_v1\method.py", line 143, in __call__
    return wrapped_func(*args, **kwargs)
  File "D:\Program Files\Python\Python37\lib\site-packages\google\api_core\retry.py", line 286, in retry_wrapped_func
    on_error=on_error,
  File "D:\Program Files\Python\Python37\lib\site-packages\google\api_core\retry.py", line 184, in retry_target
    return target()
  File "D:\Program Files\Python\Python37\lib\site-packages\google\api_core\timeout.py", line 214, in func_with_timeout
    return func(*args, **kwargs)
  File "D:\Program Files\Python\Python37\lib\site-packages\google\api_core\grpc_helpers.py", line 59, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.DeadlineExceeded: 504 Deadline Exceeded
>>> 

错误似乎来自

response = client.synthesize_speech(synthesis_input, voice, audio_config)

我是Google API的新手,不熟悉他们的代码,请有人帮忙,谢谢

0 个答案:

没有答案