Class: Google::Cloud::Speech::Stream
- Inherits:
-
Object
- Object
- Google::Cloud::Speech::Stream
- Includes:
- MonitorMixin
- Defined in:
- lib/google/cloud/speech/stream.rb
Overview
Stream
A resource that represents the streaming requests and responses.
Instance Method Summary collapse
-
#on_complete {|callback| ... } ⇒ Object
Register to be notified when the end of the audio stream has been reached.
-
#on_error {|callback| ... } ⇒ Object
Register to be notified of an error recieved during the stream.
-
#on_interim {|callback| ... } ⇒ Object
Register to be notified on the reception of an interim result.
-
#on_result {|callback| ... } ⇒ Object
Register to be notified on the reception of a final result.
-
#on_speech_end {|callback| ... } ⇒ Object
Register to be notified when speech has ceased to be detected in the audio stream.
-
#on_speech_start {|callback| ... } ⇒ Object
Register to be notified when speech has been detected in the audio stream.
-
#on_utterance {|callback| ... } ⇒ Object
Register to be notified when the server has detected the end of the user's speech utterance and expects no additional speech.
-
#results ⇒ Array<Result>
The speech recognition results for the audio.
-
#send(bytes) ⇒ Object
Sends audio content to the server.
-
#start ⇒ Object
Starts the stream.
-
#started? ⇒ boolean
Checks if the stream has been started.
-
#stop ⇒ Object
Stops the stream.
-
#stopped? ⇒ boolean
Checks if the stream has been stopped.
Instance Method Details
#on_complete {|callback| ... } ⇒ Object
Register to be notified when the end of the audio stream has been reached.
378 379 380 381 382 |
# File 'lib/google/cloud/speech/stream.rb', line 378 def on_complete &block synchronize do @callbacks[:complete] << block end end |
#on_error {|callback| ... } ⇒ Object
Register to be notified of an error recieved during the stream.
467 468 469 470 471 |
# File 'lib/google/cloud/speech/stream.rb', line 467 def on_error &block synchronize do @callbacks[:error] << block end end |
#on_interim {|callback| ... } ⇒ Object
Register to be notified on the reception of an interim result.
205 206 207 208 209 |
# File 'lib/google/cloud/speech/stream.rb', line 205 def on_interim &block synchronize do @callbacks[:interim] << block end end |
#on_result {|callback| ... } ⇒ Object
Register to be notified on the reception of a final result.
247 248 249 250 251 |
# File 'lib/google/cloud/speech/stream.rb', line 247 def on_result &block synchronize do @callbacks[:result] << block end end |
#on_speech_end {|callback| ... } ⇒ Object
Register to be notified when speech has ceased to be detected in the audio stream.
337 338 339 340 341 |
# File 'lib/google/cloud/speech/stream.rb', line 337 def on_speech_end &block synchronize do @callbacks[:speech_end] << block end end |
#on_speech_start {|callback| ... } ⇒ Object
Register to be notified when speech has been detected in the audio stream.
296 297 298 299 300 |
# File 'lib/google/cloud/speech/stream.rb', line 296 def on_speech_start &block synchronize do @callbacks[:speech_start] << block end end |
#on_utterance {|callback| ... } ⇒ Object
Register to be notified when the server has detected the end of the
user's speech utterance and expects no additional speech. Therefore,
the server will not process additional audio. The client should stop
sending additional audio data. This event only occurs when utterance
is true
.
426 427 428 429 430 |
# File 'lib/google/cloud/speech/stream.rb', line 426 def on_utterance &block synchronize do @callbacks[:utterance] << block end end |
#results ⇒ Array<Result>
The speech recognition results for the audio.
169 170 171 172 173 |
# File 'lib/google/cloud/speech/stream.rb', line 169 def results synchronize do @results end end |
#send(bytes) ⇒ Object
Sends audio content to the server.
113 114 115 116 117 118 119 120 121 |
# File 'lib/google/cloud/speech/stream.rb', line 113 def send bytes start # lazily call start if the stream wasn't started yet # TODO: do not send if stopped? synchronize do req = V1beta1::StreamingRecognizeRequest.new( audio_content: bytes.encode("ASCII-8BIT")) @request_queue.push req end end |
#start ⇒ Object
Starts the stream. The stream will be started in the first #send call.
67 68 69 70 71 72 73 |
# File 'lib/google/cloud/speech/stream.rb', line 67 def start return if @request_queue @request_queue = EnumeratorQueue.new(self) @request_queue.push @streaming_recognize_request Thread.new { background_run } end |
#started? ⇒ boolean
Checks if the stream has been started.
79 80 81 82 83 |
# File 'lib/google/cloud/speech/stream.rb', line 79 def started? synchronize do !(!@request_queue) end end |
#stop ⇒ Object
Stops the stream. Signals to the server that no more data will be sent.
126 127 128 129 130 131 132 |
# File 'lib/google/cloud/speech/stream.rb', line 126 def stop synchronize do return if @request_queue.nil? @request_queue.push self @stopped = true end end |
#stopped? ⇒ boolean
Checks if the stream has been stopped.
138 139 140 141 142 |
# File 'lib/google/cloud/speech/stream.rb', line 138 def stopped? synchronize do @stopped end end |