Next IVR

IVR, web and mobile programming for contact center technology.

Making quick recordings with Powershell


When I need recordings for an application and I want to make sure my recording script is accurate, I can either record all the voice files in my voice (bleh!) or use the Windows speech engine to generate some quick recordings. I use the opposite gender of the default TTS engine, so I'll definitely notice when a recording is missing and text to speech is kicking in. This Powershell script is for development purposes only!!!

script.tab

name    script
1.wav   Hello and welcome.
2.wav   Thanks for calling.  Bye!

script-to-wavs.ps1

Add-Type -AssemblyName System.Speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer

# Set the file format to basic/wav that IVR systems recognize
$format = New-Object System.Speech.AudioFormat.SpeechAudioFormatInfo(
    8000, 
    [System.Speech.AudioFormat.AudioBitsPerSample]::Eight, 
    [System.Speech.AudioFormat.AudioChannel]::Mono)

# See which voices are available on your system
$info = $speak.GetInstalledVoices().VoiceInfo

#Set the voice.
$speak.SelectVoice('Microsoft Zira Desktop')
$target = 'C:\Users\public\Documents\to-record\'


$a = Import-Csv -Delimiter "`t"  -Path ($target+'script.tab')
$a | foreach {
    $speak.setOutputToWaveFile($target+$_.name, $format); 
    # This writes the sound file
    $speak.Speak($_.script)
}

#The last sound file is not released until you dispose the object
$speak.Dispose()