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, language: nil, sample_rate: nil) ⇒ Audio
Returns a new Audio instance from the given source.
-
#operation(id) ⇒ Operation
Performs asynchronous speech recognition.
-
#process(source, encoding: nil, sample_rate: nil, language: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil, words: nil) ⇒ Operation
(also: #long_running_recognize, #recognize_job)
Performs asynchronous speech recognition.
-
#project_id ⇒ Object
(also: #project)
The Speech project connected to.
-
#recognize(source, encoding: nil, language: nil, sample_rate: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil, words: nil) ⇒ Array<Result>
Performs synchronous speech recognition.
-
#stream(encoding: nil, language: nil, sample_rate: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil, words: nil, utterance: nil, interim: nil) ⇒ Stream
(also: #stream_recognize)
Creates a Stream object to perform bidirectional streaming speech-recognition: receive results while sending audio.
Instance Method Details
#audio(source, encoding: nil, language: nil, sample_rate: nil) ⇒ Audio
Returns a new Audio instance from the given source. No API call is made.
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/google/cloud/speech/project.rb', line 187 def audio source, encoding: nil, language: nil, sample_rate: nil if source.is_a? Audio audio = source.dup else audio = Audio.from_source source, self end audio.encoding = encoding unless encoding.nil? audio.language = language unless language.nil? audio.sample_rate = sample_rate unless sample_rate.nil? audio end |
#operation(id) ⇒ Operation
Performs asynchronous speech recognition. Requests are processed asynchronously, meaning a Operation is returned once the audio data has been sent, and can be refreshed to retrieve recognition results once the audio data has been processed.
617 618 619 620 621 622 |
# File 'lib/google/cloud/speech/project.rb', line 617 def operation id ensure_service! grpc = service.get_op id Operation.from_grpc grpc end |
#process(source, encoding: nil, sample_rate: nil, language: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil, words: nil) ⇒ Operation Also known as: long_running_recognize, recognize_job
Performs asynchronous speech recognition. Requests are processed asynchronously, meaning a Operation is returned once the audio data has been sent, and can be refreshed to retrieve recognition results once the audio data has been processed.
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/google/cloud/speech/project.rb', line 453 def process source, encoding: nil, sample_rate: nil, language: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil, words: nil ensure_service! audio_obj = audio source, encoding: encoding, language: language, sample_rate: sample_rate 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, words: words) grpc = service.recognize_async audio_obj.to_grpc, config Operation.from_grpc grpc end |
#project_id ⇒ Object Also known as: project
The Speech project connected to.
79 80 81 |
# File 'lib/google/cloud/speech/project.rb', line 79 def project_id service.project end |
#recognize(source, encoding: nil, language: nil, sample_rate: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil, words: 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.
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/google/cloud/speech/project.rb', line 315 def recognize source, encoding: nil, language: nil, sample_rate: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil, words: nil ensure_service! audio_obj = audio source, encoding: encoding, language: language, sample_rate: sample_rate 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, words: words) grpc = service.recognize_sync audio_obj.to_grpc, config grpc.results.map do |result_grpc| Result.from_grpc result_grpc end end |
#stream(encoding: nil, language: nil, sample_rate: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil, words: nil, utterance: nil, interim: nil) ⇒ Stream Also known as: stream_recognize
Creates a Stream object to perform bidirectional streaming speech-recognition: receive results while sending audio.
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 |
# File 'lib/google/cloud/speech/project.rb', line 568 def stream encoding: nil, language: nil, sample_rate: nil, max_alternatives: nil, profanity_filter: nil, phrases: nil, words: nil, utterance: nil, interim: nil ensure_service! grpc_req = V1::StreamingRecognizeRequest.new( streaming_config: V1::StreamingRecognitionConfig.new( { config: audio_config(encoding: convert_encoding(encoding), language: language, sample_rate: sample_rate, max_alternatives: max_alternatives, profanity_filter: profanity_filter, phrases: phrases, words: words), single_utterance: utterance, interim_results: interim }.delete_if { |_, v| v.nil? } ) ) Stream.new service, grpc_req end |