Class: ESpeak::Speech

Inherits:
Object
  • Object
show all
Defined in:
lib/espeak/speech.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, options = {}) ⇒ Speech

filename - The file that will be generated options - Posible key, values

:voice     - use voice file of this name from espeak-data/voices. ie 'en', 'de', ...
:pitch     - pitch adjustment, 0 to 99
:speed     - speed in words per minute, 80 to 370
:capital   - increase emphasis of capitalized letters by raising pitch by this amount
             no range given in man but good range is 10-40 to start
:quiet     - remove printing to stdout. Affects only lame (default false)


14
15
16
17
# File 'lib/espeak/speech.rb', line 14

def initialize(text, options={})
  @text = text
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/espeak/speech.rb', line 3

def options
  @options
end

#textObject (readonly)

Returns the value of attribute text.



3
4
5
# File 'lib/espeak/speech.rb', line 3

def text
  @text
end

Instance Method Details

#bytesObject

Returns mp3 file bytes as a result of Text-To-Speech conversion.



43
44
45
46
47
48
49
50
51
# File 'lib/espeak/speech.rb', line 43

def bytes()
  speech = bytes_wav
  res = IO.popen(std_lame_command(command_options), 'r+') do |process|
    process.write(speech)
    process.close_write
    process.read
  end
  res.to_s
end

#bytes_wavObject

Returns wav file bytes as a result of Text-To-Speech conversion.



56
57
58
59
60
# File 'lib/espeak/speech.rb', line 56

def bytes_wav()
  IO.popen(espeak_command(command_options, "--stdout"), 'r') do |process|
    process.read
  end
end

#save(filename) ⇒ Object

Generates mp3 file as a result of Text-To-Speech conversion.



30
31
32
33
34
35
36
37
38
# File 'lib/espeak/speech.rb', line 30

def save(filename)
  speech = bytes_wav
  res = IO.popen(lame_command(filename, command_options), 'r+') do |process|
    process.write(speech)
    process.close_write
    process.read
  end
  res.to_s
end

#speakObject

Speaks text



21
22
23
24
25
# File 'lib/espeak/speech.rb', line 21

def speak
  IO.popen(espeak_command(command_options), 'r') do |process|
    process.read
  end
end