Building a TTS spoken 7-day weather forecast .wav file

For the fun of it, I thought I’d give a 7-Day forecast to my RadioDJ installation for playback in the morning–and maybe at other points throughout the day. After a bit of tinkering, I’ve come up with a solution that’ll pull my local forecast and speak it into a waveform file, which I have imported into RDJ as a “variable duration”–see my previous post for a quick explanation of that RDJ file-type.

In a folder under RDJ, I put the executable and dlls from GNUWin32’s wget port, and a little .vbs script (for TTS conversion) from the Jampal mp3 Library.

Next, I put together a batch file and a powershell script that would process the NWS Forecast information and create the waveform:

nws.bat:

@echo off
CD C:\RadioDJ\Media\NWS
:: get the forecast
wget ftp://tgftp.nws.noaa.gov/data/forecasts/zone/ky/kyz037.txt

:: remove header, end characters
for /f "skip=14 delims=$$" %%a in (kyz037.txt) do (
echo %%a >>forecast.tmp1
)

:: put text into one line (for TTS readability)
setlocal DisableDelayedExpansion
(for /F "usebackq delims=" %%a in (forecast.tmp1) do (
set /P "=%%a" < NUL )) > forecast.tmp

:: filter NWS abbreviations (and certain words) and replace with TTS friendly pronunciation values
powershell -command .\nws-filter.ps1

:: read the forecast into a WAV (NOTE: uses the 'default' computer voice)
cscript ptts.vbs -w forecast.wav -s 48000 -c 1 -r 2 < forecast.txt

:: cleanup the temp files
del *.tmp*
del *.txt

nws-filter.ps1:

$lookupTable = @{
'50s' = 'FIFTIES'
'60s' = 'SIXTIES'
'70s' = 'SEVENTIES'
'80s' = 'EIGHTIES'
'90s' = 'NINETIES'
'100s' = 'ONE-HUNDREDS'
'mph' = 'MILES-PER-HOUR'
'winds' = 'WINNEDS'
}

$original_file = 'forecast.tmp'
$destination_file = 'forecast.txt'

Get-Content -Path $original_file | ForEach-Object {
$line = $_

$lookupTable.GetEnumerator() | ForEach-Object {
if ($line -match $_.Key)
{
$line = $line -replace $_.Key, $_.Value
}
}
$line
} | Set-Content -Path $destination_file

…personally, I love the change I have to make to “winds” 😉

The powershell script can be edited later, for when I inevitably run across other words that aren’t pronounced right. Other filtering may be mandatory with other voices/engines… For example, the default voice I’m using–Microsoft Speech Server ZiraPro–will skip over ellipsis, whereas Microsoft Anna reads them as dot-dot-dot. Your mileage may vary.

…I guess the next thing I have to figure out is how to handle “immediate” bulletins… 😉

 

2 thoughts on “Building a TTS spoken 7-day weather forecast .wav file”

  1. hello, i’m going to try this setup, however i have to assume it will be plain TTS, is there any command line tool to place a background music under this? like something that can take the generated audio and mix it with a piece of bed music?

    1. Been a while since I tinkered with this stuff, so this isn’t going to be the greatest answer…

      To go a command line route, I’d see about trying to play with ffmpeg or maybe mencoder. (When I messed with audio in command line I usually had best luck with ffmpeg)

      …if you try ffmpeg, I think I found an answer:

      https://stackoverflow.com/questions/14498539/how-to-overlay-two-audio-files-using-ffmpeg

      I remember that when I was playing my files back through radiodj I had created a special bed that was several minutes long–since the length of my WX file varied day to day, and I created an event or playlist or something that cued the bed, played the WX, and faded the bed on completion of WX playback. I can’t remember how I did it, but I know there’s an answer in the RDJ forums somewhere, if you’re using that.

Leave a Reply

Your email address will not be published. Required fields are marked *