class Gemmy::Components::WordSpeaker::Sentence
Constants
- DefaultGap
- DefaultPitch
- DefaultSpeed
Public Class Methods
new( sentence:, syllables: 8, syllable_length: 0.2, path: nil, cached: false, silent: false )
click to toggle source
# File lib/gemmy/patches_loaded/components/word_speaker.rb, line 29 def initialize( sentence:, syllables: 8, syllable_length: 0.2, path: nil, cached: false, silent: false ) @sentence = sentence @sentence_syllables = @sentence.syllable_count.to_f @syllables = syllables.to_f @path = path @syllable_length = syllable_length.to_f @total_len = syllable_length * @syllables @cached = cached @silent = silent @idx = 0 end
Public Instance Methods
save_to_file()
click to toggle source
# File lib/gemmy/patches_loaded/components/word_speaker.rb, line 44 def save_to_file return self if @sentence.empty? || cached `espeak -v english-us -w #{path} "#{sentence}"` sentence_len = `soxi -D #{path}`.to_f diff = 1 / (total_len / sentence_len) tmp_path = "wav/tmp.wav" `sox #{path} #{tmp_path} tempo #{diff.round(2)}` `rm #{path}` `mv #{tmp_path} #{path}` self end
speak_file()
click to toggle source
# File lib/gemmy/patches_loaded/components/word_speaker.rb, line 56 def speak_file return self if @sentence.empty? || silent `aplay #{path}` self end