我在训练我的耳朵阅读摩尔斯电码;)红宝石:生成摩尔斯电码声音文件
训练自己,我已经写了一个小的Ruby脚本生成使用命令行sox
(见下文)的声音文件。它基本上只需要预制声音文件dit
s,dah
s和多个空格(在dit
s和dah
s之间,字母之间和单词之间)并将它们粘合在一起。它可以工作,但目标文件越大,速度越慢。
有没有更聪明的方式来产生与红宝石的声音成wav文件?
#!/usr/bin/ruby
wordlength = 5
blocklength = 12
testlength = 5
alphabet = [ "G", "A", "S", "5", "D", "0", "R", "/", "2", "L", "9", "T", "V", "I", "O", "Q", "C", "4", "F", "X", "E", "N", "U" ]
playstring = ""
block = ""
page = ""
MORSE = {
"!" => "---.", "\"" => ".-..-.", "$" => "...-..-", "'" => ".----.",
"(" => "-.--.", ")" => "-.--.-", "+" => ".-.-.", "," => "--..--",
"-" => "-....-", "." => ".-.-.-", "/" => "-..-.", "0" => "-----",
"1" => ".----", "2" => "..---", "3" => "...--", "4" => "....-", "5" => ".....",
"6" => "-....", "7" => "--...", "8" => "---..", "9" => "----.", ":" => "---...",
";" => "-.-.-.", "=" => "-...-", "?" => "..--..", "@" => ".--.-.", "A" => ".-",
"B" => "-...", "C" => "-.-.", "D" => "-..", "E" => ".", "F" => "..-.",
"G" => "--.", "H" => "....", "I" => "..", "J" => ".---", "K" => "-.-",
"L" => ".-..", "M" => "--", "N" => "-.", "O" => "---", "P" => ".--.",
"Q" => "--.-", "R" => ".-.", "S" => "...", "T" => "-", "U" => "..-",
"V" => "...-", "W" => ".--", "X" => "-..-", "Y" => "-.--", "Z" => "--..",
"[" => "-.--.", "]" => "-.--.-", "_" => "..--.-",
"ka" => "-.-.-.",
}
startblock = "dit.wav ditspace.wav dit.wav ditspace.wav dit.wav ditspace.wav dah.wav wordspace.wav dit.wav ditspace.wav dit.wav ditspace.wav dit.wav ditspace.wav dah.wav wordspace.wav dit.wav ditspace.wav dit.wav ditspace.wav dit.wav ditspace.wav dah.wav wordspace.wav dah.wav ditspace.wav dit.wav ditspace.wav dah.wav ditspace.wav dit.wav ditspace.wav dah.wav wordspace.wav wordspace.wav wordspace.wav "
endblock = "dit.wav ditspace.wav dah.wav ditspace.wav dit.wav ditspace.wav dah.wav ditspace.wav dit.wav blockspace.wav "
playstring << "uebungsanfang.wav wordspace.wav "
system ('/opt/local/bin/sox ' + playstring.to_s + ' tmp.wav 2>/dev/null')
system ('mv tmp.wav tmp2.wav')
playstring = ""
testlength.times do |line|
printf line.to_s + " "
playstring << "gruppe" + (line+1).to_s + ".wav wordspace.wav "
playstring << startblock
system ('/opt/local/bin/sox tmp2.wav ' + playstring.to_s + ' tmp.wav 2>/dev/null')
system ('mv tmp.wav tmp2.wav')
playstring = ""
blocklength.times do |count|
word = alphabet.sample.to_s + alphabet.sample.to_s + alphabet.sample.to_s + alphabet.sample.to_s + alphabet.sample.to_s
word.each_char do |char|
MORSE[char].each_char do |dahdit|
case dahdit
when '.' then playstring << "dit.wav "
when '-' then playstring << "dah.wav "
end
playstring << "ditspace.wav "
end
playstring << "letterspace.wav "
system ('/opt/local/bin/sox tmp2.wav ' + playstring.to_s + ' tmp.wav 2>/dev/null')
system ('mv tmp.wav tmp2.wav')
playstring = ""
end
playstring << "wordspace.wav "
block << word.to_s + " "
end
playstring << endblock
playstring << "blockspace.wav "
system ('/opt/local/bin/sox tmp2.wav ' + playstring.to_s + ' tmp.wav') #2>/dev/null
system ('mv tmp.wav tmp2.wav')
playstring = ""
page << "%02d" %(line+1).to_s + ": VVV <ak> " + block + "+" + "\n"
block = ""
end
playstring << "uebungsende.wav"
system ('/opt/local/bin/sox tmp2.wav ' + playstring.to_s + ' tmp.wav 2>/dev/null') # &
system ('rm tmp2.wav')
system ('mv tmp.wav cw.wav')
system ('lame --cbr -b 128 cw.wav cw.mp3')
system ('rm cw.wav')
puts
puts page
的声音文件使用预先生成的袜:
sox -e floating-point -r 22500 -n -t wav - synth 0.3 sin 0 > letterspace.wav
含有这些文件等。(试验,试验结束时,组的一个,两个的开头,...)
say -v Steffi --file-format=WAVE [email protected] -o uebungsanfang.wav "Anfang der Übung."
我已经上传的文件(最多为“GRUP:使用Mac OS X命令say
产生pe 5“,即。 “5组”)在这里: https://docs.google.com/open?id=0B4QwMfBGRCjVbE5iZHpHMHBKT3c
谢谢,我怀疑IO是问题所在。我会尽快尝试你的建议(也就是说,只要我在办公室;)。 – Christian