Class: Google::Cloud::Speech::InterimResult

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

Overview

InterimResult

A streaming speech recognition result corresponding to a portion of the audio that is currently being processed.

See Project#stream and Stream#on_interim.

Examples:

require "google/cloud/speech"

speech = Google::Cloud::Speech.new

stream = speech.stream encoding: :linear16,
                       language: "en-US",
                       sample_rate: 16000

# register callback for when an interim result is returned
stream.on_interim do |final_results, interim_results|
  interim_result = interim_results.first
  puts interim_result.transcript # "how old is the Brooklyn Bridge"
  puts interim_result.confidence # 0.9826789498329163
  puts interim_result.stability # 0.8999
end

# Stream 5 seconds of audio from the microphone
# Actual implementation of microphone input varies by platform
5.times do
  stream.send MicrophoneInput.read(32000)
end

stream.stop

See Also:

Instance Attribute Summary collapse

Instance Attribute Details

#alternativesArray<Result::Alternative> (readonly)

Additional recognition hypotheses (up to the value specified in max_alternatives).

Returns:



177
178
179
# File 'lib/google/cloud/speech/result.rb', line 177

def alternatives
  @alternatives
end

#confidenceFloat (readonly)

The confidence estimate between 0.0 and 1.0. A higher number means the system is more confident that the recognition is correct. This field is typically provided only for the top hypothesis. A value of 0.0 is a sentinel value indicating confidence was not set.

Returns:

  • (Float)

    the current value of confidence



177
178
179
# File 'lib/google/cloud/speech/result.rb', line 177

def confidence
  @confidence
end

#stabilityFloat (readonly)

An estimate of the probability that the recognizer will not change its guess about this interim result. Values range from 0.0 (completely unstable) to 1.0 (completely stable). Note that this is not the same as confidence, which estimates the probability that a recognition result is correct.

Returns:

  • (Float)

    the current value of stability



177
178
179
# File 'lib/google/cloud/speech/result.rb', line 177

def stability
  @stability
end

#transcriptString (readonly)

Transcript text representing the words that the user spoke.

Returns:

  • (String)

    the current value of transcript



177
178
179
# File 'lib/google/cloud/speech/result.rb', line 177

def transcript
  @transcript
end