Class: Typecast::Models::TTSWithTimestampsResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/typecast/timestamps.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(audio:, audio_format:, audio_duration:, words: [], characters: []) ⇒ TTSWithTimestampsResponse

Returns a new instance of TTSWithTimestampsResponse.



46
47
48
49
50
51
52
# File 'lib/typecast/timestamps.rb', line 46

def initialize(audio:, audio_format:, audio_duration:, words: [], characters: [])
  @audio = audio
  @audio_format = audio_format
  @audio_duration = audio_duration
  @words = words
  @characters = characters
end

Instance Attribute Details

#audioObject (readonly)

Returns the value of attribute audio.



34
35
36
# File 'lib/typecast/timestamps.rb', line 34

def audio
  @audio
end

#audio_durationObject (readonly)

Returns the value of attribute audio_duration.



34
35
36
# File 'lib/typecast/timestamps.rb', line 34

def audio_duration
  @audio_duration
end

#audio_formatObject (readonly)

Returns the value of attribute audio_format.



34
35
36
# File 'lib/typecast/timestamps.rb', line 34

def audio_format
  @audio_format
end

#charactersObject (readonly)

Returns the value of attribute characters.



34
35
36
# File 'lib/typecast/timestamps.rb', line 34

def characters
  @characters
end

#wordsObject (readonly)

Returns the value of attribute words.



34
35
36
# File 'lib/typecast/timestamps.rb', line 34

def words
  @words
end

Class Method Details

.from_h(hash) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/typecast/timestamps.rb', line 36

def self.from_h(hash)
  new(
    audio: hash.fetch("audio", ""),
    audio_format: hash.fetch("audio_format", AUDIO_WAV),
    audio_duration: hash.fetch("audio_duration", 0).to_f,
    words: hash.fetch("words", []).map { |item| AlignmentSegmentWord.from_h(item) },
    characters: hash.fetch("characters", []).map { |item| AlignmentSegmentCharacter.from_h(item) }
  )
end

Instance Method Details

#audio_bytesObject



54
55
56
# File 'lib/typecast/timestamps.rb', line 54

def audio_bytes
  Base64.decode64(audio)
end

#save_audio(path) ⇒ Object



58
59
60
# File 'lib/typecast/timestamps.rb', line 58

def save_audio(path)
  File.binwrite(path, audio_bytes)
end

#to_srtObject



62
63
64
# File 'lib/typecast/timestamps.rb', line 62

def to_srt
  caption_lines(webvtt: false)
end

#to_vttObject



66
67
68
# File 'lib/typecast/timestamps.rb', line 66

def to_vtt
  "WEBVTT\n\n#{caption_lines(webvtt: true)}"
end