Page 1 of 1

Aaron's "Weed Trek Computor Voice"

Posted: 22 Mar 2019, 15:05
by WeedTrek
:geek: Hi, it's Aaron and I'm back! I haven't been back here since the big hack years ago when we lost our stuff... but I got back into coding and thought I'd share with you my latest weird tool... the Weed Trek Computor Voice:
(723.81 KiB) Downloaded 46 times

- 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)

- unpack script folder from ""
- download FFMPEG for Windows from here:
- 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!

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

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
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
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

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

~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)

Gui, Submit, NoHide
ControlFocus, Edit1, Computor Voice ;-- mouse focus back in edit box


Re: Aaron's "Weed Trek Computor Voice"

Posted: 23 Mar 2019, 20:44
by WeedTrek
Upgrade! This thing needed some reverb to add realism. You'll need reverb.wav, unpack it and drop it in "files" folder:
(41.16 KiB) Downloaded 33 times
Here are the 5 updated FFMPEG lines, replace the existing ones with these:

Code: Select all

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%\temp1.wav",, Hide ;-- applies EQ and compression
RunWait, %comspec% /c files\ffmpeg.exe -y -i "files\chirp.wav" -i "%A_Temp%\temp1.wav" -filter_complex [0:a][1:a]concat=n=2:v=0:a=1 "%A_Temp%\temp2.wav",, Hide ;-- joins chirp.wav and saved WAV file
RunWait, %comspec% /c files\ffmpeg.exe -y -i "%A_Temp%\temp2.wav" -i files\reverb.wav -lavfi afir "%A_Temp%\temp3.wav",, Hide ;-- makes reverb response
RunWait, %comspec% /c files\ffmpeg.exe -y -i "%A_Temp%\temp3.wav" -filter:a "volume=12" "%A_Temp%\temp4.wav",, Hide ;-- turns up reverb response 10db
RunWait, %comspec% /c files\ffmpeg.exe -y -i "%A_Temp%\temp2.wav" -i "%A_Temp%\temp4.wav" -filter_complex "[0:0][1:0] amix=inputs=2" "%A_Temp%\temp5.wav",, Hide ;-- merges audio with reverb response
RunWait, %comspec% /c files\ffmpeg.exe -y -i "%A_Temp%\temp5.wav" -af silenceremove=stop_periods=-1:stop_duration=0.1:stop_threshold=-60dB "%WavFile%",, Hide ;-- removes silence, 0.1 second chunks under 60db
and add this underneath (before return) if you want to clean up the temp files:

Code: Select all

Loop, 5                   ;-- one loop per temp file created
    FileDelete, %A_Temp%\temp%A_Index%.wav ;-- deletes all 5 files
Yah I know you're all veterans, but I like the added FFMPEG functionalities which come along automatically by changing those lines of code. Comments welcome :)
I'm going to add a reverb slider to adjust how much reverb is mixed into the final wav file, from none to lots.