Class: ESpeak::Speech

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

Overview

Speech represents an Text-To-Speech audio that can be played or saved to file

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 :amplitude - amplitude adjustment, 0 to 200 :quiet - remove printing to stdout. Affects only lame (default false)



18
19
20
21
# File 'lib/espeak/speech.rb', line 18

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/espeak/speech.rb', line 6

def options
  @options
end

#textObject (readonly)

Returns the value of attribute text.



6
7
8
# File 'lib/espeak/speech.rb', line 6

def text
  @text
end

Instance Method Details

#bytesObject

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



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

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.



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

def bytes_wav
  IO.popen(espeak_command(command_options, '--stdout'), 'r', &:read)
end

#save(filename) ⇒ Object

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



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

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



25
26
27
# File 'lib/espeak/speech.rb', line 25

def speak
  IO.popen(espeak_command(command_options), 'r', &:read)
end