0
votes

Hey guys so I want to use Speech Recognition while streaming a video and want to use alternative language codes. Clearly in the package of streaming recognition on Google Cloud under the RecognitionConfig protocol there is a alternative_language_codes[] parameter which takes a list of up to 3 alternative languages. https://cloud.google.com/speech-to-text/docs/reference/rpc/google.cloud.speech.v1p1beta1#google.cloud.speech.v1p1beta1.StreamingRecognizeRequest

My code is:

    second_lang = 'el-GR'

    config = types.RecognitionConfig(
    encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=RATE,
    language_code=language_code,
    alternative_language_codes=[second_lang])

but I get an error:

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

Any idea what might be wrong?

1
No, speechV1 has no alternative_language_codes field. speechV1Beta does. So youre probably not using the Beta version.Ahmet
I use these:from future import division import re import sys from google.cloud import speech from google.cloud.speech import enums from google.cloud.speech import types import pyaudio from six.moves import queueNickolas Newton

1 Answers

1
votes

These worked as Ahmet said speech_v1p1beta1 has the alternative_language_codes parameter.

from __future__ import division

import re
import sys

from google.cloud import speech_v1p1beta1
from google.cloud.speech_v1p1beta1 import enums
from google.cloud.speech_v1p1beta1 import types
import pyaudio
from six.moves import queue