Skip to content

Instantly share code, notes, and snippets.

Created May 31, 2011 05:02
Show Gist options
  • Save anonymous/999891 to your computer and use it in GitHub Desktop.
Save anonymous/999891 to your computer and use it in GitHub Desktop.
#!ruby -Ks
require 'rubygems'
require 'ffi'
module VoiceText
extend FFI::Library
ffi_lib('vt_jpn')
class INT < FFI::Struct
layout :val, :int
end
attach_function(:VT_GetTTSInfo_JPN, [:int, :pointer, :pointer, :int], :int)
attach_function(:VT_LOADTTS_JPN, [:ulong, :int, :pointer, :pointer], :short)
attach_function(:VT_TextToFile_JPN, [:int, :pointer, :pointer, :int, :int, :int, :int, :int, :int, :int], :short)
attach_function(:VT_UNLOADTTS_JPN, [:int], :void)
VT_LOAD_SUCCESS_CODE = 4
VT_FILE_API_FMT_S16PCM_WAVE = 4
VOICES = {
:haruka => [6, 'synthesis/Haruka/'],
:show => [1, 'synthesis/Show/']
}
def self.save(text, file, s=:show)
speaker = VOICES[s]
if speaker
infoval = INT.new
if VT_GetTTSInfo_JPN(VT_LOAD_SUCCESS_CODE, nil, infoval, infoval.size) == 0
if VT_LOADTTS_JPN(0, speaker[0], speaker[1], nil) == infoval[:val]
begin
VT_TextToFile_JPN(VT_FILE_API_FMT_S16PCM_WAVE,
text, file, speaker[0], -1, -1, -1, -1, -1, -1)
ensure
VT_UNLOADTTS_JPN(speaker[0])
end
else
warn "error VT_LOADTTS_JPN"
end
end
else
warn "unknow speaker"
end
end # def
end # module
VoiceText.save("吾輩は猫である。名前はまだ無い。", "test.wav", :show)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment