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
-
#complete? ⇒ Boolean
Whether all speech recognition results have been returned.
-
#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 received 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_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.
-
#wait_until_complete! ⇒ Object
Blocks until all speech recognition results have been returned.
Instance Method Details
#complete? ⇒ Boolean
Whether all speech recognition results have been returned.
214 215 216 217 218 |
# File 'lib/google/cloud/speech/stream.rb', line 214 def complete? synchronize do @complete end end |
#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 received during the stream.
471 472 473 474 475 |
# File 'lib/google/cloud/speech/stream.rb', line 471 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.
290 291 292 293 294 |
# File 'lib/google/cloud/speech/stream.rb', line 290 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.
334 335 336 337 338 |
# File 'lib/google/cloud/speech/stream.rb', line 334 def on_result &block synchronize do @callbacks[:result] << 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
.
427 428 429 430 431 |
# File 'lib/google/cloud/speech/stream.rb', line 427 def on_utterance &block synchronize do @callbacks[:utterance] << block end end |
#results ⇒ Array<Result>
The speech recognition results for the audio.
177 178 179 180 181 |
# File 'lib/google/cloud/speech/stream.rb', line 177 def results synchronize do @results end end |
#send(bytes) ⇒ Object
Sends audio content to the server.
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/google/cloud/speech/stream.rb', line 117 def send bytes start # lazily call start if the stream wasn't started yet # TODO: do not send if stopped? synchronize do req = V1::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.
68 69 70 71 72 73 74 |
# File 'lib/google/cloud/speech/stream.rb', line 68 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.
80 81 82 83 84 |
# File 'lib/google/cloud/speech/stream.rb', line 80 def started? synchronize do !(!@request_queue) end end |
#stop ⇒ Object
Stops the stream. Signals to the server that no more data will be sent.
131 132 133 134 135 136 137 |
# File 'lib/google/cloud/speech/stream.rb', line 131 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.
143 144 145 146 147 |
# File 'lib/google/cloud/speech/stream.rb', line 143 def stopped? synchronize do @stopped end end |
#wait_until_complete! ⇒ Object
Blocks until all speech recognition results have been returned.
249 250 251 252 253 254 255 256 |
# File 'lib/google/cloud/speech/stream.rb', line 249 def wait_until_complete! complete_check = nil synchronize { complete_check = @complete } while complete_check.nil? sleep 1 synchronize { complete_check = @complete } end end |