Class: Glaemscribe::API::TTS

Inherits:
Object
  • Object
show all
Defined in:
lib/api/tts.rb

Constant Summary collapse

TTS_ENGINE_PATH =
File.dirname(__FILE__) + "/../../lib_espeak/espeakng.for.glaemscribe.nowasm.sync.js"
TTS_MODULE_PATH =
File.dirname(__FILE__) + "/../../lib_espeak/glaemscribe_tts.js"

Class Method Summary collapse

Class Method Details

.ipa(text, voice, has_raw_mode) ⇒ Object



36
37
38
39
# File 'lib/api/tts.rb', line 36

def self.ipa(text, voice, has_raw_mode)
  load_engine if !@context
  @context.eval("var esp = new Glaemscribe.TTS(); esp.synthesize_ipa(#{text.inspect},{voice:'#{voice}', has_raw_mode: #{has_raw_mode}})")
end

.load_engineObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/api/tts.rb', line 13

def self.load_engine
  return if @context
  
  @context                    = ::MiniRacer::Context.new
  
  @context.attach 'console.log',  proc{|o| puts o}
  @context.attach 'print',        proc{|o| puts o}
  
  espeak_lib                  = File.open(TTS_ENGINE_PATH,"rb").read
  @context.eval(espeak_lib)

  tts_module                  = File.open(TTS_MODULE_PATH,"rb").read    
  @context.eval(tts_module)

  @voice_list = @context.eval("Glaemscribe.TTS.voice_list()")
#        puts "TTS Engine loaded."
end

.loaded?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/api/tts.rb', line 9

def self.loaded?
  !@context.nil?
end

.option_name_to_voice(option_name) ⇒ Object



46
47
48
# File 'lib/api/tts.rb', line 46

def self.option_name_to_voice(option_name)
  option_name.downcase.gsub(/^espeak_voice_/,'').gsub('_','-')
end

.voice_listObject



31
32
33
34
# File 'lib/api/tts.rb', line 31

def self.voice_list
  load_engine if !@context
  @voice_list
end

.wav(text, voice, has_raw_mode) ⇒ Object



41
42
43
44
# File 'lib/api/tts.rb', line 41

def self.wav(text, voice, has_raw_mode)
  load_engine if !@context
  @context.eval("var esp = new Glaemscribe.TTS(); esp.synthesize_wav(#{text.inspect},{voice:'#{voice}', has_raw_mode: #{has_raw_mode}})")
end