Search code examples
configgoogle-cloud-speech

google-cloud-speech speech.types.RecognitionConfig


I am current running on Debian 8 Jessie with Python 2.7 and the current google-cloud-speech and storage (pip'd in with upgrade today). When I attempt to config it fails with:

ValueError: Protocol message RecognitionConfig has no "enable_automatic_punctuation" field.

from this call:

config = speech.types.RecognitionConfig(
    encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=8000,
    language_code='en-US',
    # Enable automatic punctuation
    enable_automatic_punctuation=True)

The call was directly copy/paste'd from "https://cloud.google.com/speech-to-text/docs/automatic-punctuation#speech-enhanced-model-python".

Huh?


Solution

  • enable_automatic_punctuation is only available if you import speech_v1p1beta1 instead of speech_v1. Compare the documentation for RecognitionConfig for both beta and non beta.

    Also, in the very same example that you have linked, if you click on View on Github, you can see the following import:

    from google.cloud import speech_v1p1beta1 as speech

    Also, related to this topic.

    EDIT:

    Also, that code is on Python 3, and you are using Python 2.7, be aware of that.