RadioDJ - Free Radio Automation Software Forum

More or Less Radio Talk => Software and Utilities => Topic started by: Compdoggie on June 08, 2018, 12:28:18 PM

Title: Autohotkey and Text to Speech
Post by: Compdoggie on June 08, 2018, 12:28:18 PM
Hello, I have posted some ideas in the past here and most of those posts were removed due to old age!  ::)

Autohotkey is a free and easy script package and once installed on your windows computer, all you have to do the double click or run the script.  Do a google search for autohotkey and you will find lots of information. There is even forums where many are happy to help you get your script working just as you need it. There is even a few programs that will record your mouse clicks and save them as macros in autohotkey script.  The possibility's to automate many items working with RadioDJ is possible.

Autohotkey even allows you to compile your script in to an executable  (.exe)  But, if you run your scripts as a .ahk ' you can mod the script at any time in a text editor, I like notepad++ because it has line numbers and you can easily debug your scripts.

Text to Speech and autohotkey is something I have been using for many years and even though a plugin was made for RDJ, I still prefer to use the script based method because I can quickly and easily make changes as needed.

Windows OS has built-in text to speech engine located in windows control panel/ speech recognition/ text to speech/  You can find with a little searching many voices that can be easily installed on your pc.

The text to speech plugin for radiodj makes .wav files to mix properly with rdj sound output and is very good, however, for me, the voice would come in too quick and some late night announcers allow the music to cross fade slowly and then start announcing. This delay is easy to control with a autohotkey script.  Speech scripts use windows audio out and so a virtual mixer or external mixer may be required to get the proper balance from voice over music.

I will post the following script I am currently using and if you read line by line, you can see the possibilities, over the years I have simplified what I like, but I have many versions, where you can do trivial data base and comment on bands, have multiple calls for different voices, like a female voice to give time and weather and a male voice to announce the artist and title. You can have many voices as long as they do not overlap, the sapi voice engine is not good at multi-tasking.

Here is the script and to use it, you would copy and paste into a text editor and save as announcer1.ahk or something like that. I have over 24 of these scripts in a directory and use RDJ events to call up the script every hour to announce the rotation, time and dj etc...

Read the ; comments in the script to understand whats happening  Note:not placing in script quotes to make this easier to read

;Begin script
; Voice announce Zera @ 1am playing ambient until 9am
; ahk script by Compdoggie
#persistent
#SingleInstance force
;2hours is -7072000 time is in ticks or basically in seconds  my scripts time out and kill themselves before RDJ next event when a new ;script is called up
SetTimer, KillScript, -3540000 ;59 minutes til stop
; SetTimer, Announcement1, 1800000 ;30mins -leave off minus sign for repeat function time is minutesX60X1000
{
   Sleep 5000 ;35000 new lead in

Gui, Add, Button, r2 w195 , Voice 2 Zira ; Gui to make small window to show that script is running
Gui, Show,x1065 y23, Synth01
Gosub Saytime

SetTimer, modtime, 500
return

modtime:
FileGetTime, NewModTime, D:\nowplaying.txt
if (NewModTime != LastModTime)
{
    LastModTime := NewModTime
    gosub, GetNowPlaying
}
return

GetNowPlaying:
    Loop, read, D:\nowplaying.txt  ; here is the nowplaying text file that RDJ creates this loop constantly looks for a refresh to read
        last_line := A_LoopReadLine


Newstring := RegExReplace(last_line, "[^A-Za-z \-']+", "")
Newstringfinal := RegExReplace(NewString, "-", "`,")
Newstringfinal := RegExReplace(NewString, "DEVO", "`DeeVoh") ; some ways to make the voice say something better
Newstringfinal := RegExReplace(NewString, "REM", "`R E M ")
If Newstringfinal contains PSA,NPR,UNK ; if the string contains any of these it will not announce good for PSA, songs with talking at ;beginning
    Return

SayFile:
    Random, rand, 1, 15 ; set the value to the number of variations in the announcement saybefore or after 15 random sayings
    SayString := ["heres a track, from " newstringfinal " , enjoy "
      ,"now playing, is " newstringfinal " , nice sound from this track "
      ,"This music is by " newstringfinal " , very talented musicians made this one! "
      ,"next up, from " newstringfinal " ,stay with us as we fly through the soundscape of ambient space!"
      ,"music from " newstringfinal " , the best on the sound lab radio network"
      ,"you might like this from " newstringfinal " , we think you will like this one!"
      ,"check this, from " newstringfinal " ,groove and, enjoy."
      ,"heres music from " newstringfinal " , ambient chill at it's finest I must say... "
      ,"music now, from " newstringfinal " , one of my favorites!, we hope you like it"
      ,"check this tune from " newstringfinal " , a special track, just for you-"
      ,"now heres music from " newstringfinal " , sound art in motion"
      ,"check this track from " newstringfinal " , thats one of the best pieces, on the sound lab Radio Network"
      ,"This is the place for " newstringfinal " , sometimes you just gotta chill , only on the sound lab Radio Network"
      ,"check this piece from " newstringfinal " , I must say, we play great music!" 
      ,"Good stuff from " newstringfinal " ,on the sound lab Radio network, Enjoy-"]
v := ComObjCreate("SAPI.SpVoice")
v.Voice := v.GetVoices().Item(2) ; set the voice  2 is the voice number on my computer
v.rate := -2 ; slow down speak   
v.Speak(SayString[rand]) ; announce music
return

SayTime:
   FormatTime, SayHour, %A_Now%, h ; get current hour
   FormatTime, SayMinute, %A_Now%, m ; get current minutes
   FormatTime, SayAMPM, %A_Now%, tt ; get AM/PM
   
   If(SayMinute>0 && SayMinute<10) ; add the "oh" for minutes 1 through nine
      SayMinute = oh %SayMinute%
   If(SayMinute=0) ; if the current minute is 0, say oh clock instead of zero
      SayMinute = oh clock
   IfInString, SayAMPM, AM ; If AM, say a m instead of ameters
      SayAMPM = a- m
   IfInString, SayAMPM, PM ; If PM, say p m instead of pmeters
      SayAMPM = p m
;if you want to say time, then insert the following after saytimestring = It's %SayHour% %SayMinute% %SayAMPM% ,
   SayTimeString =  It's one A M , continuing with more ambient, space, chill with your host, Earth Theina  ; announce time once and present radio show
v := ComObjCreate("SAPI.SpVoice")
v.Voice := v.GetVoices().Item(2) ; set the voice 
v.rate := -2 ; slow down speak   
v.Speak(SayTimeString)
sleep 5000
Return

; Announcement1:
; SayTimeString = You are listening to the Free Synth Radio Network ;end
; v := ComObjCreate("SAPI.SpVoice")
; v.Voice := v.GetVoices().Item(2) ; set the voice 
; v.rate := -2 ; slow down speak   
; v.Speak(SayTimeString)
; sleep 5000
; Return

ButtonOk:
ExitApp
return

   ExitApp
}
Return

KillScript:
ExitApp

;end script

Currently running this script with radiodjv2   I run a 1tb drive with c:\ as 200 gig OS and a D:\ as the Radio:\ drive for mariadb, shoutcast, a-----t encoder, radiodjv2 dir running 2.0.0.3 

Hope this sheds some light on text to speech and the awesome tool called autokhotkey!

Thanks to Marius for such an enjoyable addition to my life!  :ok: RadioDJ!