【问题标题】:google cloud synthetizes speech 501 Method not foundgoogle cloud 合成语音 501 Method not found
【发布时间】:2018-06-19 15:49:01
【问题描述】:

严格使用作为示例提供的代码来运行谷歌云文本到语音 api:

def synthesize_text(text):
    """Synthesizes speech from the input string of text."""
    from google.cloud import texttospeech
    client = texttospeech.TextToSpeechClient()

    input_text = texttospeech.types.SynthesisInput(text=text)

    # Note: the voice can also be specified by name.
    # Names of voices can be retrieved with client.list_voices().
    voice = texttospeech.types.VoiceSelectionParams(
        language_code='en-US',
        ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE)

    audio_config = texttospeech.types.AudioConfig(
        audio_encoding=texttospeech.enums.AudioEncoding.MP3)

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

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

我收到了上述错误消息google.api_core.exceptions.MethodNotImplemented 501 Method not found

这似乎是 Google 内部错误。我已经仔细检查了我的凭据。 错误来自这个特定的line: response = client.synthesize_speech(input_text, voice, audio_config)

请帮忙。

【问题讨论】:

  • 你使用的是v1还是v1beta1
  • 在 api 仪表板中,请求来自 'texttospeech.v1'

标签: python google-api google-cloud-platform gcloud google-text-to-speech


【解决方案1】:

此时,由于某种原因,python 客户端库有code for v1 and v1beta1 API versions。然而,检查the dicovery service for Google APIs,我们可以看到唯一可用的端点是v1beta1。

如果您关注this library docs 并使用from google.cloud import texttospeech_v1,您的客户将尝试使用https://texttospeech.googleapis.com/v1/ 而不是https://texttospeech.googleapis.com/v1beta1/。错误不是 4XX 而是 5XX 的事实让我认为端点本身可能存在,但它们尚未实现,或者您不允许发现它们(所以它们看起来没有实现)。

尝试将您的导入更改为v1beta1 doc (from google.cloud import texttospeech_v1beta1) 中的那个,看看这是否有任何不同。

【讨论】:

    猜你喜欢
    • 2019-05-12
    • 1970-01-01
    • 2018-12-30
    • 2014-03-04
    • 1970-01-01
    • 2018-01-23
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多