Class: FlowSpeech::Audio
- Inherits:
-
Object
- Object
- FlowSpeech::Audio
- Defined in:
- lib/flowspeech/client.rb
Instance Attribute Summary collapse
-
#audio_base64 ⇒ Object
readonly
Returns the value of attribute audio_base64.
-
#bits_per_sample ⇒ Object
readonly
Returns the value of attribute bits_per_sample.
-
#mime_type ⇒ Object
readonly
Returns the value of attribute mime_type.
-
#num_channels ⇒ Object
readonly
Returns the value of attribute num_channels.
-
#quota ⇒ Object
readonly
Returns the value of attribute quota.
-
#sample_rate ⇒ Object
readonly
Returns the value of attribute sample_rate.
Instance Method Summary collapse
- #bytes ⇒ Object
-
#initialize(data) ⇒ Audio
constructor
A new instance of Audio.
- #write(path) ⇒ Object
Constructor Details
#initialize(data) ⇒ Audio
Returns a new instance of Audio.
27 28 29 30 31 32 33 34 |
# File 'lib/flowspeech/client.rb', line 27 def initialize(data) @mime_type = data.fetch("mimeType") @audio_base64 = data.fetch("audioBase64") @quota = data["quota"] @sample_rate = data.fetch("sampleRate") @num_channels = data.fetch("numChannels") @bits_per_sample = data.fetch("bitsPerSample") end |
Instance Attribute Details
#audio_base64 ⇒ Object (readonly)
Returns the value of attribute audio_base64.
25 26 27 |
# File 'lib/flowspeech/client.rb', line 25 def audio_base64 @audio_base64 end |
#bits_per_sample ⇒ Object (readonly)
Returns the value of attribute bits_per_sample.
25 26 27 |
# File 'lib/flowspeech/client.rb', line 25 def bits_per_sample @bits_per_sample end |
#mime_type ⇒ Object (readonly)
Returns the value of attribute mime_type.
25 26 27 |
# File 'lib/flowspeech/client.rb', line 25 def mime_type @mime_type end |
#num_channels ⇒ Object (readonly)
Returns the value of attribute num_channels.
25 26 27 |
# File 'lib/flowspeech/client.rb', line 25 def num_channels @num_channels end |
#quota ⇒ Object (readonly)
Returns the value of attribute quota.
25 26 27 |
# File 'lib/flowspeech/client.rb', line 25 def quota @quota end |
#sample_rate ⇒ Object (readonly)
Returns the value of attribute sample_rate.
25 26 27 |
# File 'lib/flowspeech/client.rb', line 25 def sample_rate @sample_rate end |
Instance Method Details
#bytes ⇒ Object
36 37 38 39 40 |
# File 'lib/flowspeech/client.rb', line 36 def bytes Base64.strict_decode64(audio_base64) rescue ArgumentError => e raise Error, "FlowSpeech returned invalid base64 audio: #{e.}" end |
#write(path) ⇒ Object
42 43 44 45 |
# File 'lib/flowspeech/client.rb', line 42 def write(path) File.binwrite(path, bytes) path end |