Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/festivaltts4r/festival4r.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.execute(cmd) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/festivaltts4r/festival4r.rb', line 51

def self.execute(cmd)
  begin
    out = IO.popen(cmd)
    Process.wait
    e = $?.exitstatus
  rescue StandardError => err
    raise FestivalError.new(err)
  else
    raise FestivalSystemError.new("0 not returned:\n#{cmd}\n#{out.readlines}"
      ) unless e.eql?(0)
  end
end

Instance Method Details

#to_mp3(filename, params = {}) ⇒ Object

Creates a file with name “filename” and with the generated with festival tts, the string itself and lame. Can handle one options:

  • text –> speech given text instead of the string itself.

  • text2wave - alternative text2wave program and options besides ‘text2wave’

  • lame - alternative lame command other than ‘lame –alt-preset cbr 16 -a –resample 11 –lowpass 5 –athtype 2 -X3 -’



40
41
42
43
44
45
46
47
48
49
# File 'lib/festivaltts4r/festival4r.rb', line 40

def to_mp3(filename, params={})
  text = params[:text] || self
  text2wave = params[:text2wave] || "text2wave"
  # athtype not on all LAMEs, i.e. --athtype 2 
  lame = params[:lame] || "lame --alt-preset cbr 16 -a --resample 11 --lowpass 5 -X3 -"
  raise "to_mp3 language option still not implemented" if params[:language]
  cmd = "echo \"#{text.to_s}\" | #{text2wave} | #{lame} > #{filename} 2>&1"

  self.class.execute cmd
end

#to_speech(params = {}) ⇒ Object

Outputs the speech generated with festival tts and the string itself. Can handle these options:

  • text –> speech given text instead of the string itself.

  • language –> speech language desired (festival voices for given languages are required )

  • festival –> alternative festival program and options besides ‘festival –tts’



24
25
26
27
28
29
30
31
32
33
# File 'lib/festivaltts4r/festival4r.rb', line 24

def to_speech(params={})  
  text = params[:text] || self
  festival = params[:festival] || "festival --tts"
  language = "--language " + params[:language] if params[:language]

  cmd = "echo \"#{text.to_s}\" | #{festival} #{language} 2>&1"

  self.class.execute cmd

end