Class: Google::Cloud::Speech::Project
- Inherits:
-
Object
- Object
- Google::Cloud::Speech::Project
- Defined in:
- lib/google/cloud/speech/project.rb
Overview
Project
The Google Cloud Speech API enables developers to convert audio to text by applying powerful neural network models. The API recognizes over 80 languages and variants, to support your global user base. You can transcribe the text of users dictating to an application's microphone, enable command-and-control through voice, or transcribe audio files, among many other use cases. Recognize audio uploaded in the request, and integrate with your audio storage on Google Cloud Storage, by using the same technology Google uses to power its own products.
Instance Method Summary collapse
-
#audio(source, encoding: nil, sample_rate: nil, language: nil) ⇒ Audio
Returns a new Audio instance from the given source.
-
#project ⇒ Object
The Speech project connected to.
-
#recognize(source, encoding: nil, sample_rate: nil, language: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil) ⇒ Array<Result>
Performs synchronous speech recognition.
-
#recognize_job(source, encoding: nil, sample_rate: nil, language: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil) ⇒ Job
Performs asynchronous speech recognition.
Instance Method Details
#audio(source, encoding: nil, sample_rate: nil, language: nil) ⇒ Audio
Returns a new Audio instance from the given source. No API call is made.
168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/google/cloud/speech/project.rb', line 168 def audio source, encoding: nil, sample_rate: nil, language: nil if source.is_a? Audio audio = source.dup else audio = Audio.from_source source, self end audio.encoding = encoding unless encoding.nil? audio.sample_rate = sample_rate unless sample_rate.nil? audio.language = language unless language.nil? audio end |
#project ⇒ Object
The Speech project connected to.
76 77 78 |
# File 'lib/google/cloud/speech/project.rb', line 76 def project service.project end |
#recognize(source, encoding: nil, sample_rate: nil, language: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil) ⇒ Array<Result>
Performs synchronous speech recognition. Sends audio data to the Speech API, which performs recognition on that data, and returns results only after all audio has been processed. Limited to audio data of 1 minute or less in duration.
The Speech API will take roughly the same amount of time to process audio data sent synchronously as the duration of the supplied audio data. That is, if you send audio data of 30 seconds in length, expect the synchronous request to take approximately 30 seconds to return results.
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/google/cloud/speech/project.rb', line 278 def recognize source, encoding: nil, sample_rate: nil, language: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil ensure_service! audio_obj = audio source, encoding: encoding, sample_rate: sample_rate, language: language config = audio_config( encoding: audio_obj.encoding, sample_rate: audio_obj.sample_rate, language: audio_obj.language, max_alternatives: max_alternatives, profanity_filter: profanity_filter, phrases: phrases) grpc = service.recognize_sync audio_obj.to_grpc, config grpc.results.map do |result_grpc| Result.from_grpc result_grpc end end |
#recognize_job(source, encoding: nil, sample_rate: nil, language: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil) ⇒ Job
Performs asynchronous speech recognition. Requests are processed asynchronously, meaning a Job is returned once the audio data has been sent, and can be refreshed to retrieve recognition results once the audio data has been processed.
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/google/cloud/speech/project.rb', line 386 def recognize_job source, encoding: nil, sample_rate: nil, language: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil ensure_service! audio_obj = audio source, encoding: encoding, sample_rate: sample_rate, language: language config = audio_config( encoding: audio_obj.encoding, sample_rate: audio_obj.sample_rate, language: audio_obj.language, max_alternatives: max_alternatives, profanity_filter: profanity_filter, phrases: phrases) grpc = service.recognize_async audio_obj.to_grpc, config Job.from_grpc grpc, service end |