Class: Google::Cloud::Speech::Audio
- Inherits:
-
Object
- Object
- Google::Cloud::Speech::Audio
- Defined in:
- lib/google/cloud/speech/audio.rb
Overview
Audio
Represents a source of audio data, with related metadata such as the audio encoding, sample rate, and language.
See Project#audio.
Instance Attribute Summary collapse
-
#encoding ⇒ String, Symbol
Encoding of audio data to be recognized.
-
#language ⇒ String, Symbol
The language of the supplied audio as a BCP-47 language code.
-
#sample_rate ⇒ Integer
Sample rate in Hertz of the audio data to be recognized.
Instance Method Summary collapse
-
#recognize(max_alternatives: nil, profanity_filter: nil, phrases: nil) ⇒ Array<Result>
Performs synchronous speech recognition.
-
#recognize_job(max_alternatives: nil, profanity_filter: nil, phrases: nil) ⇒ Job
Performs asynchronous speech recognition.
Instance Attribute Details
#encoding ⇒ String, Symbol
Encoding of audio data to be recognized.
Acceptable values are:
raw
- Uncompressed 16-bit signed little-endian samples. (LINEAR16)flac
- The Free Lossless Audio Codec encoding. Only 16-bit samples are supported. Not all fields in STREAMINFO are supported. (FLAC)mulaw
- 8-bit samples that compand 14-bit audio samples using G.711 PCMU/mu-law. (MULAW)amr
- Adaptive Multi-Rate Narrowband codec. (sample_rate
must be 8000 Hz.) (AMR)amr_wb
- Adaptive Multi-Rate Wideband codec. (sample_rate
must be 16000 Hz.) (AMR_WB)
83 84 85 |
# File 'lib/google/cloud/speech/audio.rb', line 83 def encoding @encoding end |
#language ⇒ String, Symbol
The language of the supplied audio as a BCP-47 language code. If not specified, the language defaults to "en-US". See Language Support for a list of the currently supported language codes.
121 122 123 |
# File 'lib/google/cloud/speech/audio.rb', line 121 def language @language end |
#sample_rate ⇒ Integer
Sample rate in Hertz of the audio data to be recognized. Valid values are: 8000-48000. 16000 is optimal. For best results, set the sampling rate of the audio source to 16000 Hz. If that's not possible, use the native sample rate of the audio source (instead of re-sampling).
101 102 103 |
# File 'lib/google/cloud/speech/audio.rb', line 101 def sample_rate @sample_rate end |
Instance Method Details
#recognize(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.
187 188 189 190 191 192 193 194 195 |
# File 'lib/google/cloud/speech/audio.rb', line 187 def recognize max_alternatives: nil, profanity_filter: nil, phrases: nil ensure_speech! speech.recognize self, encoding: encoding, sample_rate: sample_rate, language: language, max_alternatives: max_alternatives, profanity_filter: profanity_filter, phrases: phrases end |
#recognize_job(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.
235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/google/cloud/speech/audio.rb', line 235 def recognize_job max_alternatives: nil, profanity_filter: nil, phrases: nil ensure_speech! speech.recognize_job self, encoding: encoding, sample_rate: sample_rate, language: language, max_alternatives: max_alternatives, profanity_filter: profanity_filter, phrases: phrases end |