Skip to content

Speak-Text

Speaks text by the default text-to-speech voice

#requires -version 5.1

param([string]$text = "")

try {
	if ($text -eq "") { $text = Read-Host "Enter the text to speak" }

	$Voice = new-object -ComObject SAPI.SPVoice
	[void]$Voice.Speak($text)
	exit 0 # success
} catch {
	"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}

Specifies the text to read

An interactive directory of PowerShell scripts.