Class: Google::Cloud::Speech::Job
- Inherits:
-
Object
- Object
- Google::Cloud::Speech::Job
- 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.
Instance Method Summary collapse
-
#done? ⇒ boolean
Checks if the speech-recognition processing of the audio data is complete.
-
#reload! ⇒ Object
(also: #refresh!)
Reloads the job with current data from the long-running, asynchronous processing of a speech-recognition operation.
-
#results ⇒ Array<Result>
A speech recognition result corresponding to a portion of the audio.
-
#wait_until_done! ⇒ Object
Reloads the job until the operation is complete.
Instance Method Details
#done? ⇒ boolean
Checks if the speech-recognition processing of the audio data is complete.
109 110 111 |
# File 'lib/google/cloud/speech/job.rb', line 109 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.
129 130 131 132 |
# File 'lib/google/cloud/speech/job.rb', line 129 def reload! @grpc = @service.get_op @grpc.name self end |
#results ⇒ Array<Result>
A speech recognition result corresponding to a portion of the audio.
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/google/cloud/speech/job.rb', line 81 def results return nil unless done? return nil unless @grpc.result == :response resp = V1beta1::AsyncRecognizeResponse.decode(@grpc.response.value) resp.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.
151 152 153 154 155 156 157 158 159 |
# File 'lib/google/cloud/speech/job.rb', line 151 def wait_until_done! backoff = ->(retries) { sleep 2 * retries + 5 } retries = 0 until done? backoff.call retries retries += 1 reload! end end |