Last active
June 3, 2020 15:33
-
-
Save knoopx/27d3631ed96b3eb97a1b5fc96287f35e to your computer and use it in GitHub Desktop.
OpenTX Sound Generator
This file contains 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
# Get a list by executing: say -v "?" | |
# Install more from Accessibility -> Speech | |
VOICE = "Samantha" | |
DEFAULT_MESSAGES = File.read("en-US-taranis.csv").lines.reduce({}) do |result, line| | |
path, filename, message = line.chomp.split(";") | |
result[File.join(path, File.basename(filename, ".*"))] = message | |
result | |
end | |
OVERRIDES = { | |
"SOUNDS/en/SYSTEM/hello" => "Welcome to OpenTX", | |
"SOUNDS/en/SYSTEM/rssi_org" => "rf signal low!", | |
"SOUNDS/en/SYSTEM/rssi_red" => "rf signal critical!", | |
"SOUNDS/en/siglow" => "r f signal low!", | |
"SOUNDS/en/sigcrt" => "r f signal critical!", | |
"SOUNDS/en/d" => "d", | |
"SOUNDS/en/dsetpt" => "d set point", | |
"SOUNDS/en/i" => "i", | |
"SOUNDS/en/p" => "p", | |
} | |
task :default do | |
DEFAULT_MESSAGES.merge(OVERRIDES).each do |subpath, message| | |
aiff_path = File.join("aiff", subpath + ".aiff") | |
FileUtils.mkdir_p(File.dirname(aiff_path)) | |
system "say", "-v", VOICE, message, "-o", aiff_path | |
wav_path = File.join("wav", subpath + ".wav") | |
FileUtils.mkdir_p(File.dirname(wav_path)) | |
system "sox", aiff_path, "-b", "16", "-r", "16000", wav_path | |
end | |
end | |
task :demo, [:message] do |t, args| | |
voices = `say -v "?"`.lines.map{|l| l.split.take(2) } | |
voices.filter{|name, locale| locale.start_with?("en_US") }.each do |name,| | |
puts "Voice: #{name}" | |
system "say", "-v", name, args.fetch(:message, "Hello world") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment