From 66c9f533e0b4d2884635abf96ae40e49d75714f4 Mon Sep 17 00:00:00 2001 From: ZomgPonies Date: Sat, 25 Jan 2014 23:08:05 -0500 Subject: [PATCH] Text2voice --- code/__HELPERS/unsorted.dm | 35 +++++++++++++++++++++++++++++++++++ scripts/voice.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 scripts/voice.py diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index 90446e59589..4c53337a2b7 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -1572,3 +1572,38 @@ proc/check_target_facings(mob/living/initator, mob/living/target) return 2 if(initator.dir + 2 == target.dir || initator.dir - 2 == target.dir || initator.dir + 6 == target.dir || initator.dir - 6 == target.dir) //Initating mob is looking at the target, while the target mob is looking in a direction perpendicular to the 1st return 3 + + +/proc/texttospeechstrip(var/t_in) + var/t_out = "" + for(var/i=1, i<=length(t_in), i++) + var/ascii_char = text2ascii(t_in,i) + switch(ascii_char) + // A .. Z + if(65 to 90) //Uppercase Letters + if(lentext(t_out) <= 150) + t_out += ascii2text(ascii_char) + // a .. z + if(97 to 122) //Lowercase Letters + if(lentext(t_out) <= 150) + t_out += ascii2text(ascii_char) + // 0 .. 9 + if(48 to 57) //Numbers + if(lentext(t_out) <= 150) + t_out += ascii2text(ascii_char) + // ` , - . ! ? : ' + if(39,44,45,46,33,63,58,96,60,62) //Common name punctuation + if(lentext(t_out) <= 150) + t_out += ascii2text(ascii_char) + //Space + if(32) + if(lentext(t_out) <= 150) + t_out += ascii2text(ascii_char) + return t_out +/var/lastspeak = "" + + +/mob/proc/texttospeech(var/text, var/speed, var/pitch, var/accent, var/voice, var/echo) + text = texttospeechstrip(text) + lastspeak = text + ext_python("voice.py", "\"[accent]\" \"[voice]\" \"[pitch]\" \"[echo]\" \"[speed]\" \"[text]\" \"[src.ckey]\"") \ No newline at end of file diff --git a/scripts/voice.py b/scripts/voice.py new file mode 100644 index 00000000000..47d25a31615 --- /dev/null +++ b/scripts/voice.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python2 +''' +WINDOWS ONLY! +You need espeak: http://sourceforge.net/projects/espeak/files/espeak/espeak-1.47/espeak-1.47.11-win.zip/download +SOund eXchange (sox): http://sourceforge.net/projects/sox/files/sox/14.4.1/sox-14.4.1a-win32.zip/download +and WinVorbis for OggEnc: http://winvorbis.stationplaylist.com/WinVorbisSetup.exe +''' +import sys, os, re, string +from subprocess import call +accent = sys.argv[1] +voice = sys.argv[2] +pitch = sys.argv[3] +echo = sys.argv[4] +speed = sys.argv[5] +text = sys.argv[6] +ckey = sys.argv[7] +espeakpath = "C:/Program Files (x86)/eSpeak/command_line/" +playervoicespath = "C:/Users/Administrator/Dropbox/Baystation12/sound/playervoices/" +soxpath = "C:/Program Files (x86)/sox-14-4-1/" +oggencpath = "C:/Program Files (x86)/WinVorbis/" +text = string.replace(text, "39", "'") +command = "\""+espeakpath+"espeak.exe\" -w "+playervoicespath+""+ckey+"u.wav -v"+accent+""+voice+" \""+text+"\" -p "+pitch+" -s "+speed+" -a 100" +# First we make the voice file, sounds/playervoice/keyu.wav +call(command, shell=True) +command2 = "\""+soxpath+"sox.exe\" "+playervoicespath+""+ckey+"u.wav \""+playervoicespath+""+ckey+".wav\" echo 1 0.5 "+echo+" .5" +# Now we apply effects to it, like echo (there's lots of other effects too) +call(command2, shell=True) +#remove the old keyu.wav +os.remove(playervoicespath+""+ckey+"u.wav") +command3 = "\""+oggencpath+"OggEnc.exe\" "+playervoicespath+""+ckey+".wav" +#Now we turn key.wav into key.ogg to reduce bandwidth +call(command3, shell=True) +#delete the wav +os.remove(playervoicespath+""+ckey+".wav") +sys.exit() \ No newline at end of file