Class: Google::Cloud::Speech::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/speech/job.rb

Overview

Job

A resource represents the long-running, asynchronous processing of a speech-recognition operation. The job can be refreshed to retrieve recognition results once the audio data has been processed.

See Project#recognize_job and Audio#recognize_job.

Examples:

require "google/cloud/speech"

speech = Google::Cloud::Speech.new

job = speech.recognize_job "path/to/audio.raw",
                           encoding: :raw, sample_rate: 16000

job.done? #=> false
job.reload! # API call
job.done? #=> true
results = job.results

See Also:

Instance Method Summary collapse

Instance Method Details

#done?boolean

Checks if the speech-recognition processing of the audio data is complete.

Examples:

require "google/cloud/speech"

speech = Google::Cloud::Speech.new

job = speech.recognize_job "path/to/audio.raw",
                           encoding: :raw, sample_rate: 16000

job.done? #=> false

Returns:

  • (boolean)

    true when complete, false otherwise.



102
103
104
# File 'lib/google/cloud/speech/job.rb', line 102

def done?
  @grpc.done?
end

#reload!Object Also known as: refresh!

Reloads the job with current data from the long-running, asynchronous processing of a speech-recognition operation.

Examples:

require "google/cloud/speech"

speech = Google::Cloud::Speech.new

job = speech.recognize_job "path/to/audio.raw",
                           encoding: :raw, sample_rate: 16000

job.done? #=> false
job.reload! # API call
job.done? #=> true


122
123
124
125
# File 'lib/google/cloud/speech/job.rb', line 122

def reload!
  @grpc.reload!
  self
end

#resultsArray<Result>

A speech recognition result corresponding to a portion of the audio.

Examples:

require "google/cloud/speech"

speech = Google::Cloud::Speech.new

job = speech.recognize_job "path/to/audio.raw",
                           encoding: :raw, sample_rate: 16000

job.done? #=> true
results = job.results

Returns:

  • (Array<Result>)

    The transcribed text of audio recognized. If the job is not done this will return nil.



76
77
78
79
80
81
82
83
84
# File 'lib/google/cloud/speech/job.rb', line 76

def results
  return nil unless @grpc.response?
  @grpc.response.results.map do |result_grpc|
    Result.from_grpc result_grpc
  end
  # TODO: Ensure we are raising the proper error
  # TODO: Ensure GRPC behavior here, is an error already raised?
  # raise @grpc.error
end

#wait_until_done!Object

Reloads the job until the operation is complete. The delay between reloads will incrementally increase.

Examples:

require "google/cloud/speech"

speech = Google::Cloud::Speech.new

job = speech.recognize_job "path/to/audio.raw",
                           encoding: :raw, sample_rate: 16000

job.done? #=> false
job.wait_until_done!
job.done? #=> true


144
145
146
# File 'lib/google/cloud/speech/job.rb', line 144

def wait_until_done!
  @grpc.wait_until_done!
end