DESCRIPTION:
- Creates computerized responses from the starship's computer
- Lets user type in text and converts text to file using SP.VOICE etc
- Uses FFMPEG to create CD-quality audio WAV files automatically, saves them in script dir
- Sounds like a Star Trek computer (uses any installed Windows voice... TTS GB Hazel is best)
INSTRUCTIONS:
- unpack script folder from "ComputorVoice.zip"
- download FFMPEG for Windows from here: https://www.ffmpeg.org/download.html
- extract FFMPEG.EXE and put into "files" folder
- open "Computor Voice.exe"
- choose voice, rate and pitch
- type stuff, press ENTER
- gaze lovingly on resulting WAV files
(optional) - install any system voices which work in Windows, they can all be used
This was something I built just for me, BUT the full range of FFMPEG options are available for you to tweak with, located starting on line 54 of the AHK code. Remember, it sounds coolest with a female voice, there are lots of installable voices for Windows.
There is a trick to getting Microsoft voices to work on a 64-bit system... information is in "files" folder or look that up online.
Let me know if I've missed anything. Enjoy!
Aaron
Code: Select all
#SingleInstance, Ignore ;-- "Computor Voice Generator"
#NoTrayIcon ;-- frankensteined by Aaron Bewza, V1.0 March 21 2019
Gui, Font, s10 bold, Arial ;-- thanks to all the AHK users who figured out speech stuff
Gui, Add, Edit ,x3 y2 w120 +0x100 hWndhEdit vText -VScroll Limit1500
Gui, Add, Button, Hidden Default, OK ;--default button for ENTER key to trigger
Gui, Font, s7
SpVoice:=ComObjCreate("SAPI.SpVoice") ;-- makes a speech object
Loop, % SpVoice.GetVoices.Count {
Name:=SpVoice.GetVoices.Item(A_Index-1).GetAttribute("Name") ;-- gets voice names
if StrLen(VoiceList) ;-- if more than one voice...
VoiceList.="|" ;-- separates with delimiter
VoiceList.=Name ;-- voice names list ready to display
}
Gui, Add, DropDownList, Choose1 x3 y28 w120 vVoice gVoice, %VoiceList% ;-- available voices to choose from
Gui, Add, Text, x3 y48 w24 h20 cWhite, Rate
Gui, Add, Slider, x27 y44 w99 h24 vRate Range-10-10 ToolTip NoTicks gMouseFocus ;-- slider (rate), focus cursor in edit box
Gui, Add, Text, x3 y68 w24 h20 cWhite, Pitch
Gui, Add, Slider, x27 y64 w99 h24 vPitch Range-10-10 ToolTip NoTicks gMouseFocus ;-- slider (pitch), focus cursor in edit box
Gui, Color, red
Gui, +AlwaysOnTop +ToolWindow ;-- no minimize or taskbar button
Gui, Show, w126 h84, Computor Voice
SoundPlay, files\poweron.wav
return
ButtonOK: ;-- hidden default button (for Enter key) saves text to wav file
Gui, Submit, NoHide
if Text=
return ;-- disables saving blank file if nothing in edit box
textcut:=RegExReplace(Text, "\s*(\n|\r\n)", A_Space) ;-- removes line breaks
textcut:=RegExReplace(textcut,"[^\w]", A_Space) ;-- removes non-alphanumeric chars
textcut:=StrReplace(textcut, "_", A_Space) ;-- underscores into spaces
textcut:=StrReplace(textcut, A_Tab, A_Space) ;-- tabs into spaces
textcut:=RegExReplace(textcut, "S) +", A_Space) ;-- removes multiple spaces
textcut=%textcut% ;-- removes leading/trailing spaces
textcut:=SubStr(textcut, 1 , 50) ;-- trims length of filename to 50
if textcut= ;-- disables saving a file with a blank name
return
WavFile = %A_ScriptDir%\%textcut%.wav ;-- creates filename from doctored text
IfExist, %WavFile% ;-- denies overwriting which causes script to crash
{
SoundPlay, %WavFile% ;-- plays existing sound instead
Send, ^a ;-- highlights the text inside edit box
return
}
SpFileStream:=ComObjCreate("SAPI.SpFileStream") ;-- creates speech object
SpFileStream.Format.Type:=39 ;-- 39 chooses 48khz 16bit audio quality (???)
SpFileStream.Open(WavFile,3,false) ;-- text called for writing to file
SpVoice.AudioOutputStream:=SpFileStream ;-- applies user settings (?)
SpVoice.Rate:=Rate ;-- applies chosen rate (-10 to +10)
SpVoice.Speak("<pitch absmiddle = '" pitch "'/>",0x20) ;-- applies chosen pitch (-10 to +10)
SpVoice.Speak(Text,0x1) ;-- speaks the voice stream asynchronously into a file
rWaitUntilDone:=SpVoice.WaitUntilDone(-1) ;-- waits until finished (?)
SpFileStream.Close ;-- closes speech stream
RunWait, %comspec% /c files\ffmpeg.exe -y -i "%WavFile%" -af highpass=f=420`,lowpass=f=4500`,acompressor=threshold=-26dB:ratio=7:attack=6:release=40`,volume=18dB "%A_Temp%\tempsoundfile.wav",, Hide ;-- ffmpeg applies EQ and compression to saved WAV file
RunWait, %comspec% /c files\ffmpeg.exe -y -i "files\chirp.wav" -i "%A_Temp%\tempsoundfile.wav" -filter_complex [0:a][1:a]concat=n=2:v=0:a=1 "%WavFile%",, Hide ;-- ffmpeg joins chirp.wav and finished WAV file into output file
SoundPlay, %WavFile% ;-- plays the finished file
Send, ^a ;-- highlights the text inside edit box
return
Voice:
Gui, Submit, NoHide
SpVoice.Voice:=SpVoice.GetVoices("Name=" . Voice).Item(0) ;-- switches to chosen voice
ControlFocus, Edit1, Computor Voice ;-- mouse focus back in edit box
return
~RButton:: ;-- no line breaks when pasting into edit box with right-click
~^v:: ;-- ctrl+v can also be used to paste, might as well include it
Clipboard:=RegExReplace(Clipboard, "\s*(\n|\r\n)", A_Space)
return
MouseFocus:
Gui, Submit, NoHide
ControlFocus, Edit1, Computor Voice ;-- mouse focus back in edit box
return
GuiClose:
ExitApp