Convert Text to WAV

Call the function 'SpeakToFile' like this:

 SpeaktoFile "This file contains audio of a voice reading the sentence 'This file contains audio of a voice reading the sentence" well... you know the rest." "SampleFile.wav" 

SpeakToFile function

Here's the speakToFile function referenced above. (Yes, it needs a better name, but naming-hard etc.)

function speakToFile($message, $outputFilePath) {
	if ($null -eq $synth) {
		Add-Type -AssemblyName System.Speech
		$synth = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer
		$synth.SelectVoice("Microsoft Zira Desktop")
	}
	$counter = 0;
	# read the pipeline, just incase...
	foreach ($m in $input) {
		$synth.SetOutputToWaveFile("$outputFilePath-$counter.wav");
		$synth.speak($m);
	}

	if ($null -ne $message) {
		$synth.SetOutputToWaveFile("$outputFilePath-$counter.wav");
		$synth.speak($message);
	}

}

See also