0

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))
Jignasha Royala
  • 1,032
  • 10
  • 27

1 Answers1

0

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • thank you @Martijn . i changed the code in to the snake_case format but still the same error occurs. "ValueError: Protocol message RecognitionConfig has no "enable_automatic_punctuation" field." – isuru gayashan Apr 30 '18 at 08:15
  • @isurugayashan: are you using `google.cloud.speech_v1p1beta1`, the beta version? – Martijn Pieters Apr 30 '18 at 08:16
  • thank you @martijn the problem was with that library file. pycharm 2018.1 gave an unresolved reference error for the particular library so that i changed it to the google.cloude.speech_v1 earlier. problem solved once changed back to the google.cloud.speech_v1p1beta1. – isuru gayashan Apr 30 '18 at 08:23