Class: Typecast::Models::TTSWithTimestampsResponse
- Inherits:
-
Object
- Object
- Typecast::Models::TTSWithTimestampsResponse
- Defined in:
- lib/typecast/timestamps.rb
Instance Attribute Summary collapse
-
#audio ⇒ Object
readonly
Returns the value of attribute audio.
-
#audio_duration ⇒ Object
readonly
Returns the value of attribute audio_duration.
-
#audio_format ⇒ Object
readonly
Returns the value of attribute audio_format.
-
#characters ⇒ Object
readonly
Returns the value of attribute characters.
-
#words ⇒ Object
readonly
Returns the value of attribute words.
Class Method Summary collapse
Instance Method Summary collapse
- #audio_bytes ⇒ Object
-
#initialize(audio:, audio_format:, audio_duration:, words: [], characters: []) ⇒ TTSWithTimestampsResponse
constructor
A new instance of TTSWithTimestampsResponse.
- #save_audio(path) ⇒ Object
- #to_srt ⇒ Object
- #to_vtt ⇒ Object
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
#audio ⇒ Object (readonly)
Returns the value of attribute audio.
34 35 36 |
# File 'lib/typecast/timestamps.rb', line 34 def audio @audio end |
#audio_duration ⇒ Object (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_format ⇒ Object (readonly)
Returns the value of attribute audio_format.
34 35 36 |
# File 'lib/typecast/timestamps.rb', line 34 def audio_format @audio_format end |
#characters ⇒ Object (readonly)
Returns the value of attribute characters.
34 35 36 |
# File 'lib/typecast/timestamps.rb', line 34 def characters @characters end |
#words ⇒ Object (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_bytes ⇒ Object
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_srt ⇒ Object
62 63 64 |
# File 'lib/typecast/timestamps.rb', line 62 def to_srt caption_lines(webvtt: false) end |
#to_vtt ⇒ Object
66 67 68 |
# File 'lib/typecast/timestamps.rb', line 66 def to_vtt "WEBVTT\n\n#{caption_lines(webvtt: true)}" end |