Class: Gemmy::Components::WordSpeaker::Sentence
- Inherits:
-
Object
- Object
- Gemmy::Components::WordSpeaker::Sentence
- Defined in:
- lib/gemmy/patches_loaded/components/word_speaker.rb
Constant Summary collapse
- DefaultPitch =
1
- DefaultSpeed =
250
- DefaultGap =
10
Instance Method Summary collapse
-
#initialize(sentence:, syllables: 8, syllable_length: 0.2, path: nil, cached: false, silent: false) ⇒ Sentence
constructor
A new instance of Sentence.
- #save_to_file ⇒ Object
- #speak_file ⇒ Object
Constructor Details
#initialize(sentence:, syllables: 8, syllable_length: 0.2, path: nil, cached: false, silent: false) ⇒ Sentence
Returns a new instance of Sentence.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 |
Instance Method Details
#save_to_file ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# 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 ⇒ Object
56 57 58 59 60 |
# File 'lib/gemmy/patches_loaded/components/word_speaker.rb', line 56 def speak_file return self if @sentence.empty? || silent `aplay #{path}` self end |