Jie Jenn
Jie Jenn

Reputation: 505

Google Speech API RecognitionConfig has no "speechContexts" field error

I am using the latest Google-Cloud-Speech API (0.36.0). I am able to execute my script successfully, however, when I add the speechContexts parameter, I kept getting "ValueError: Protocol message RecognitionConfig has no "speechContexts" field." error.

I have followed the example on the Google Documentation page, but so far I have not making any progress.

Source Code:

config = types.RecognitionConfig(
            encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16,
            sample_rate_hertz = 22050,
            language_code = 'en-US',
            speechContexts = [{'phrases':['installer']}]
            )

Output

Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
ValueError: Protocol message RecognitionConfig has no "speechContexts" field.

Upvotes: 1

Views: 1893

Answers (1)

dsesto
dsesto

Reputation: 8178

The issue is that you are the field speechContexts, while according to the documentation for the RecognitionConfig class, the correct name for this field is speech_contexts instead.

You only need to change your code above, to this one:

config = types.RecognitionConfig(
            encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16,
            sample_rate_hertz = 22050,
            language_code = 'en-US',
            speech_contexts = [{'phrases':['installer']}] #Note the change in the field
            )

You can refer to the Python Reference for the Cloud Speech API in order to have the complete documentation and examples of use for the client library.

Upvotes: 3

Related Questions