Weed Trek Computor Voice v2.0

Post your working scripts, libraries and tools
User avatar
WeedTrek
Posts: 20
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Weed Trek Computor Voice v2.0

20 Apr 2019, 18:34

Weed Trek Computor Voice v2.0
by Aaron Bewza
April 20, 2019


ComputorVoiceMp3.zip
New minimal version, all required files are included.
(1.52 MiB) Downloaded 52 times

Here is the code:

Code: Select all

#SingleInstance, Ignore    ;-- "Computor Voice Generator"
#NoTrayIcon                ;-- frankensteined by Aaron Bewza, V1.0 March 21 2019
#Persistent                ;-- current version 1.1: April 09 2019

Gui, Font, s10 bold, Arial
Gui, Add, Edit ,x3 y2 w220 +0x100 hWndhEdit vtext -VScroll Limit1500
Gui, Add, Button, Hidden Default, OK ;--default button for ENTER key to trigger
Gui, Add, text, x130 y50 w96 h20 cWhite +Center vInfo, -READY-
Gui, Font, s7

gosub, FindVoices ;-- creates a list of available Windows speech voices
Gui, Add, DropDownList, Choose1 x3 y28 w122 vVoice gVoice, %VoiceList% ;-- available voices to choose from, chooses default top of list

Gui, Add, text, x3 y50 w35 h20 cWhite +Right, Rate ;-- rate (-10 to 10)
Gui, Add, Slider, x38 y46 w94 h24 vRate Range-10-10 ToolTip NoTicks gFocus
Gui, Add, text, x3 y72 w35 h20 cWhite +Right, Pitch ;-- pitch (-10 to 10)
Gui, Add, Slider, x38 y68 w94 h24 vPitch Range-10-10 ToolTip NoTicks gFocus

Gui, Add, text, x3 y92 w64 h20 cWhite, Reverb Mix: ;-- reverb audio mix (0 - 100, I like 50)
Gui, Add, text, x3 y108 w16 h20 cWhite +Right, 0
Gui, Add, text, x121 y108 w16 h20 cWhite, 100
Gui, Add, Slider, x21 y104 w98 h24 vReverbMix Range0-100 ToolTip NoTicks gFocus, 50

Gui, Add, text, x3 y126 w64 h20 cWhite, Pre`-delay: ;-- reverb predelay in milliseconds (0 - 150, I like 45)
Gui, Add, text, x3 y142 w16 h20 cWhite +Right, 0
Gui, Add, text, x118 y142 w18 h20 cWhite, 150
Gui, Add, Slider, x21 y138 w98 h24 vPreDelay Range0-150 ToolTip NoTicks gFocus, 45

Gui, Add, Button, x5 y180 w50 h16 cWhite gHelp, HELP ;-- button to open instructions

Gui, Add, Checkbox, x136 y30 cWhite vTricorder gFocus, Tricorder`? ;-- adds checkbox for outside ambience (mimics tricorder speaker)

Gui, Font, underline ;-- underlines link to Weed Trek website
Gui, Add, text, x142 y180 w74 h16 cWhite vWeedtrekLink gWebsite +Center, WEEDTREK.CA

Gui, Color, red
Gui, +ToolWindow +AlwaysOnTop ;-- no minimize or taskbar button
Gui, Show, w227 h200, Computor Voice

global CurrentCursor:=0          ;-- sets cursor caret to nothing (default)
OnMessage(0x20,  "WM_SETCURSOR") ;-- calls hand cursor caret
OnMessage(0x200, "WM_MOUSEMOVE") ;-- while hovering over link
return

ButtonOK:                      ;-- hidden default button (for Enter key) saves text to Mp3 file
Gui, Submit, NoHide
if (text="") {                 ;-- disables saving blank file if nothing in edit box
    Gui, +OwnDialogs     
    MsgBox, 48, No Correct Characters, You must type some text`! 
    ControlFocus, Edit1, Computor Voice ;-- mouse focus back in edit box
    Send, ^a                   ;-- highlights the text inside edit box
    return
    }

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, 60) ;-- trims length of filename to 60
if (textcut="") {               ;-- disables saving a file with a blank name after the above replacements
    Gui, +OwnDialogs
    MsgBox, 48, No Correct Characters, You must type some text`!
    ControlFocus, Edit1, Computor Voice ;-- mouse focus back in edit box
    Send, ^a                    ;-- highlights the text inside edit box
    return
    }

Mp3File=%A_ScriptDir%\%textcut%.mp3 ;-- creates filename variable for use in next line
if FileExist(Mp3File) {         ;-- disables overwriting same name file (causes crash, best avoided)
    Gui, +OwnDialogs
    MsgBox, 48, Cannot Overwrite, Cannot overwrite `"%textcut%.mp3`"
    ControlFocus, Edit1, Computor Voice ;-- mouse focus back in edit box
    Send, ^a                    ;-- highlights the text inside edit box
    return
    }

GuiControl,, Info, -WORKING-   ;-- changes text above hal9000

SpFileStream:=ComObjCreate("SAPI.SpFileStream") ;-- creates speech object
SpFileStream.Format.Type:=35            ;-- 35 chooses 44100hz 16bit 1411kbps (cd quality)
  Temp1Mp3=%A_Temp%\temp1.mp3           ;-- creates temp file name variable for use in next line
SpFileStream.Open(Temp1Mp3,3)           ;-- file for audio to populate
SpVoice.AudioOutputStream:=SpFileStream ;-- applies audio settings to stream
SpVoice.Rate:=Rate                      ;-- applies chosen rate (-10 to +10)
SpVoice.Speak("<pitch absmiddle='" pitch "'/>",0x20) ;-- applies chosen pitch (-10 to +10)
SpVoice.Speak(text,1)     ;-- speaks the voice stream asynchronously into a file
SpVoice.WaitUntilDone(-1) ;-- waits until stream is finished (?)
SpFileStream.Close()      ;-- finalizes file (?)

If (Tricorder="0") {            ;-- tricorder box unchecked, voice will match bridge ambience by default (for inside effect)
  Random, ChirpNumber, 1, 6   ;-- random number to choose from "inside" chirp selection
  HFDamping=50
  RoomScale=50
  StereoDepth=100
  RunWait, %comspec% /c files\sox.exe "%A_Temp%\temp1.mp3" "%A_Temp%\temp2.mp3" pad 0 10 highpass 800 lowpass 3800 compand 0.1`,0.2 1:-70`,-40`,-30 -10 -90 gain -n,, Hide
  RunWait, %comspec% /c files\sox.exe "files\audio\chirp%ChirpNumber%.mp3" "%A_Temp%\temp2.mp3" "%Mp3File%" gain -h reverb %ReverbMix% %HFDamping% %RoomScale% %StereoDepth% %PreDelay% %WetGain% silence 1 0.2 -80d -1 0.2 -80d gain -n,, Hide
  FileDelete, %A_Temp%\temp1.mp3
  FileDelete, %A_Temp%\temp2.mp3 ;-- deletes leftover temp files
  }

If (Tricorder="1") {             ;-- tricorder box checked, voice will match tricorder speaker ambience (for outside effect)
  Random, ChirpNumber, 7, 11     ;-- random number to choose from "outside" chirp selection
  RunWait, %comspec% /c files\sox.exe "%A_Temp%\temp1.mp3" "%A_Temp%\temp2.mp3" gain -h highpass 2000 lowpass 3000 compand 0.02`,0.05 0:-70`,-40`,-30 -10 -90 silence 1 0.2 -80d -1 0.2 -80d gain -n,, Hide
  RunWait, %comspec% /c files\sox.exe "files\audio\chirp%ChirpNumber%.mp3" "%A_Temp%\temp2.mp3" "%Mp3File%",, Hide
  FileDelete, %A_Temp%\temp1.mp3
  FileDelete, %A_Temp%\temp2.mp3 ;-- deletes leftover temp files
  }

SoundPlay, %Mp3File% ;-- plays the finished file

GuiControl,, Info, -READY- ;-- changes text above hal9000
ControlFocus, Edit1, Computor Voice ;-- mouse focus back in edit box
Send, ^a             ;-- highlights the text inside edit box
return

FindVoices:
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
    }
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

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

~RButton::  ;-- for 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) ;-- removes the line breaks
return

Website:
run, "http://weedtrek.ca"   ;-- opens official Weed Trek website in default browser
return

Help:
Gui, +OwnDialogs          ;-- opens help information in msgbox (how to use program)
MsgBox, 64, Instructions,
(
1- Choose voice (defaults to system)
2- Choose Pitch and Rate of voice
3- Reverb settings are all customizable
4- If outside, check Tricorder checkbox for
   outside ambience (no reverb, small speaker)
5- Type text into box, then press ENTER
6- Finished Mp3 files are in program`'s folder
)
ControlFocus, Edit1, Computor Voice ;-- mouse focus back in edit box
return

GuiClose:
ExitApp

;----------- functions -----------------------------;

WM_SETCURSOR(wParam, lParam) ;-- calls hand cursor
    {
    HitTest:=lParam & 0xFFFF
    if (HitTest=1 && CurrentCursor!=0)
        {
        DllCall("SetCursor", "ptr", CurrentCursor)
        return true
        }
    }

WM_MOUSEMOVE(wParam, lParam) ;-- sets hand cursor and tooltip text while hovering over link
    {
    static Hand:=DllCall("LoadCursor", "ptr", 0, "ptr", 32649)
    static Help:=DllCall("LoadCursor", "ptr", 0, "ptr", 32651)
    if A_GuiControl in WeedtrekLink
        {
        CurrentCursor:=Hand
        ToolTip, Visit Weed Trek
        }
    else
        {
        CurrentCursor:=0
        ToolTip
        }
    }
DESCRIPTION:
We talk to the ship's computer a lot, on our show. I needed something to create her voice, so here it is.
Works with any installed Windows voice (TTS Hazel works best (processing was tested using her voice), but others like IVONA etc can be used.

CHANGES:
- "Tricorder Mode" checkbox (if checked, outside ambience and a small tricorder speaker is applied)
- "HELP" button shows basic idea and usage
- unpacked size is 3.9mb instead of 50
- Mp3 files are used instead of WAV
- SOX is used instead of FFMPEG

TO DO:
- add the rest of the reverb controls (room size, HF damping, stereo depth)
- fix up GUI a little better

TESTED ON WINDOWS 7 (32 and 64-bit) ...not tested on Windows 10, can someone report back if it does?
User avatar
DataLife
Posts: 358
Joined: 29 Sep 2013, 19:52

Re: Weed Trek Computor Voice v2.0

20 Apr 2019, 21:32

This is a really cool script.

I am using Windows 10 64 bit, 32 bit Unicode AutoHotkey and this script works just fine.

Please just one suggestion. I put in a phrase and attempt to test each voice and some of the slider bars but every time it creates an MP3 and says it can not overwrite the MP3 when I try a different voice.

Just add a checkbox that says "Create MP3". That way we can uncheck the box and test and test and test until we find what we like without having to delete each MP3 just so we can test each feature or voice.

Or add a random number between 1 and a 1000 to the filename, which I may do anyway.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
WeedTrek
Posts: 20
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Weed Trek Computor Voice v2.0

20 Apr 2019, 22:30

excellent idea!!! wouldn't have thought of that on my own. thanks!
My Weed Trek video archive: http://weedtrek.ca
User avatar
elModo7
Posts: 141
Joined: 01 Sep 2017, 02:38
GitHub: elModo7
Location: Spain
Contact:

Re: Weed Trek Computor Voice v2.0

02 May 2019, 11:16

Man this is awesome, could be useful for external commands on some spaceish/futuristic game!
Working on x64 Win10 Pro for Workstations.
:beer:

Return to “Scripts and Functions”

Who is online

Users browsing this forum: F4Jonatas, HiSoKa, swagfag and 47 guests