param( [Parameter(Mandatory = $true)] [string]$TextPath, [Parameter(Mandatory = $true)] [string]$OutputPath, [int]$Rate = 0 ) $ErrorActionPreference = "Stop" Add-Type -AssemblyName System.Speech $text = Get-Content -LiteralPath $TextPath -Raw $synth = New-Object System.Speech.Synthesis.SpeechSynthesizer try { $synth.Rate = $Rate $synth.SetOutputToWaveFile($OutputPath) $synth.Speak($text) } finally { $synth.Dispose() }