Benjamin
Benjamin

Reputation: 23

google cloud synthetizes speech 501 Method not found

Strictly using code provided as example to run google cloud text to speech 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"')

I have got above error mesage google.api_core.exceptions.MethodNotImplemented 501 Method not found.

It seems to be a Google internal error. I've double check my credentials. Error comes from this particular line: response = client.synthesize_speech(input_text, voice, audio_config)

Please help.

Upvotes: 2

Views: 592

Answers (1)

Jofre
Jofre

Reputation: 3898

At this moment, for some reason, the python client library has code for v1 and v1beta1 API versions. However, checking the dicovery service for Google APIs, we can see that the only available endpoints are for v1beta1.

If you follow this library docs and use from google.cloud import texttospeech_v1, your client will try to use https://texttospeech.googleapis.com/v1/ instead of https://texttospeech.googleapis.com/v1beta1/. The fact that the error is not a 4XX but rather a 5XX makes me think that maybe the endpoints themselves exist, but they have not been yet implemented, or you're not allowed to discover them (so they look not implemented).

Try to change your import for the one in the v1beta1 doc (from google.cloud import texttospeech_v1beta1), and see if this makes any difference.

Upvotes: 3

Related Questions