Created
March 13, 2016 13:00
-
-
Save 844196/1a878032d4f9428a47d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open_jtalk' | |
require 'tmpdir' | |
require 'readline' | |
class Talk | |
def start | |
tmpdir = Dir.mktmpdir('syaberu.rb') | |
while string = Readline.readline('> ', true) | |
say(string, tmpdir) | |
end | |
ensure | |
FileUtils.remove_entry_secure(tmpdir) | |
end | |
private | |
def say(string, working_dir) | |
make_voicefile(string, working_dir) | |
system('play', '-q', "#{working_dir}/output.wav") | |
end | |
def make_voicefile(string, output_dir) | |
OpenJtalk.load(OpenJtalk::Config::Mei::LOW) do |openjtalk| | |
header, data = openjtalk.synthesis(openjtalk.normalize_text(string)) | |
OpenJtalk::WaveFileWriter.save("#{output_dir}/output.wav", header, data) | |
end | |
end | |
end | |
Talk.new.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment