googleapis / google-cloud-ruby

Google Cloud Client Library for Ruby
https://googleapis.github.io/google-cloud-ruby/
Apache License 2.0
1.35k stars 543 forks source link

enable_speaker_diarization not recognized in config settings even with beta #2881

Closed Rob117 closed 5 years ago

Rob117 commented 5 years ago

Environment details

Problem

enable_speaker_diarization in config settings gives ArgumentError (Unknown field name 'enable_speaker_diarization' in initialization map entry.): error.

Code example

initiaizer:

# Imports the Google Cloud client library
# Need beta for speaker identification
require "google/cloud/speech/v1p1beta1/cloud_speech_pb"

# Instantiates a client
TextToSpeech = Google::Cloud::Speech.new

Actual calling code

config = { sample_rate_hertz: 8000,
               enable_word_time_offsets: true,
               language_code: 'en-US',
               enable_speaker_diarization: true}
    audio_file = File.binread '/Users/name/Documents/stt.flac'
    audio = { content: audio_file }
    response = TextToSpeech.recognize config, audio

I specifically required the beta version thinking that would resolve the message (by requiring the beta file, although now I feel like that might not solve the issue).

Regardless, enable_speaker_diarization flag is not recognized.

I consulted the documentation at http://googleapis.github.io/google-cloud-ruby/docs/google-cloud-speech/latest/Google/Cloud/Speech/V1p1beta1/RecognitionConfig.html#enable_speaker_diarization-instance_method.

It says it's a method, but I see no way to create a RecognitionConfig object, so I passed the argument in a hash like the rest of the config settings.

quartzmo commented 5 years ago

@Rob117 Thanks for reporting this issue! Can you post the entire error backtrace?

blowmage commented 5 years ago

I see no way to create a RecognitionConfig object

You can either pass the options as arguments to the initializer:

require "google/cloud/speech/v1p1beta1"

config = Google::Cloud::Speech::V1p1beta1::RecognitionConfig.new \
  sample_rate_hertz: 8000,
  enable_word_time_offsets: true,
  language_code: 'en-US',
  enable_speaker_diarization: true

Or you can create the object and set each attribute separately:

require "google/cloud/speech/v1p1beta1"

config = Google::Cloud::Speech::V1p1beta1::RecognitionConfig.new
config.sample_rate_hertz = 8000
config.enable_word_time_offsets = true
config.language_code = 'en-US'
config.enable_speaker_diarization = true
quartzmo commented 5 years ago

@Rob117 Have you been able to give this a try?

Rob117 commented 5 years ago

@quartzmo @blowmage I just gave it a go, and it works! For those who come after:

init:
TextToSpeech = Google::Cloud::Speech.new(version: :V1p1beta1)
TTSConfig = Google::Cloud::Speech::V1p1beta1::RecognitionConfig.new sample_rate_hertz: 8000,
                                                                    enable_word_time_offsets: true,
                                                                    language_code: 'en-US',
                                                                    enable_speaker_diarization: true

some other place:
audio_file = File.binread '/Users/USER/Documents/stt.flac'
    # audio = { content: request.body }
    audio = { content: audio_file }
    response = TextToSpeech.recognize TTSConfig, audio