0
votes

i want to get a word transcript that has punctuation from google-speech-api. i am using python 3 and

i get this error when i run my code which is the exact same code sample from

https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/speech/cloud-client/beta_snippets.py.

i get an error

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

what can i do to overcome this.

def transcribe_file_with_auto_punctuation(path):
    client = speech.SpeechClient()

with io.open(path, 'rb') as audio_file:
    content = audio_file.read()
    audio = speech.types.RecognitionAudio(content=content)
    config = speech.types.RecognitionConfig(
    enableAutomaticPunctuation=True,
    encoding= speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
    languageCode= 'en-US',
    model= 'default')

response = client.recognize(config, audio)

for i, result in enumerate(response.results):
    alternative = result.alternatives[0]
    print('-' * 20)
    print('First alternative of result {}'.format(i))
    print('Transcript: {}'.format(alternative.transcript))
1

1 Answers

0
votes

The Python API names all options using the snake_case convention (lowercase words joined with underscores), so the option you want is called enable_automatic_punctuation. Note that the same applies to the language_code option:

config = speech.types.RecognitionConfig(
    enable_automatic_punctuation=True,
    encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
    language_code='en-US',
    model='default')

The sample you linked to did use the snake_case name.

Note that automatic punctuation is a new feature in the newer v1p1beta1 release of the API, so make sure you import the right class. From the API Reference section:

A new beta release, spelled v1p1beta1, is provided to provide for preview of upcoming features. In order to use this, you will want to import from google.cloud.speech_v1p1beta1 in lieu of google.cloud.speech.

And the feature may be in future be removed from the free API. As the v1p1beta1 documentation for enableAutomaticPunctuation states:

This is currently offered as an experimental service, complimentary to all users. In the future this may be exclusively available as a premium feature.