Class: FlowSpeech::Audio

Inherits:
Object
  • Object
show all
Defined in:
lib/flowspeech/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_base64Object (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_sampleObject (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_typeObject (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_channelsObject (readonly)

Returns the value of attribute num_channels.



25
26
27
# File 'lib/flowspeech/client.rb', line 25

def num_channels
  @num_channels
end

#quotaObject (readonly)

Returns the value of attribute quota.



25
26
27
# File 'lib/flowspeech/client.rb', line 25

def quota
  @quota
end

#sample_rateObject (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

#bytesObject



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.message}"
end

#write(path) ⇒ Object



42
43
44
45
# File 'lib/flowspeech/client.rb', line 42

def write(path)
  File.binwrite(path, bytes)
  path
end