Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module 'google.cloud.speech_v1p1beta1.types' has no 'RecognitionAudio' member

Trying to run the sample code and I am getting this error"

Module 'google.cloud.speech_v1p1beta1.types' has no 'RecognitionAudio' member

Env: python3x, linux, installed and updated google-cloud lib

pip install --upgrade google-cloud-speech.

Installed the following

  • google-cloud (0.34.0)
  • google-cloud-speech (0.36.3)

Not sure what else to check. Would be great if you have any suggestions

import argparse
import io

def transcribe_file_with_enhanced_model():
    """Transcribe the given audio file using an enhanced model."""
    # [START speech_transcribe_enhanced_model_beta]
    from google.cloud import speech_v1p1beta1 as speech
    client = speech.SpeechClient()

    speech_file = 'resources/commercial_mono.wav'

    with io.open(speech_file, 'rb') as audio_file:
        content = audio_file.read()

    audio = speech.types.RecognitionAudio(content=content)

    config = speech.types.RecognitionConfig(
        encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
        sample_rate_hertz=8000,
        language_code='en-US',
        # Enhanced models are only available to projects that
        # opt in for audio data collection.
        use_enhanced=True,
        # A model must be specified to use enhanced model.
        model='phone_call')

    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))
    # [END speech_transcribe_enhanced_model_beta]
like image 296
Stryker Avatar asked Feb 13 '19 00:02

Stryker


1 Answers

i think your version is "google.cloud.speech_v1" . install the google-cloud-speech 2.0.0

pip uninstall google-cloud-speech

pip install google-cloud-speech

like image 155
AkiMitu Avatar answered Sep 21 '22 16:09

AkiMitu