Skip to content

Instantly share code, notes, and snippets.

@markekraus
Created June 15, 2018 19:05
Show Gist options
  • Save markekraus/74bd0fbf34813da0fc4c7cb8f102004c to your computer and use it in GitHub Desktop.
Save markekraus/74bd0fbf34813da0fc4c7cb8f102004c to your computer and use it in GitHub Desktop.
Cheap Screen reader code for PowerShell
Function Out-Default {
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline)]
[PSObject]
$InputObject,
[switch]
$Transcript
)
begin {
if (-not $global:SpeechQueue) {
$PowerShell = [PowerShell]::Create()
$global:SpeechQueue = [System.Collections.Concurrent.BlockingCollection[String]]::new(
[System.Collections.Concurrent.ConcurrentQueue[string]]::new())
$Null = $PowerShell.AddScript({
Param(
[System.Collections.Concurrent.BlockingCollection[String]]
$SpeechQueue
)
$Null = Add-Type -AssemblyName System.Speech
$speech = [System.Speech.Synthesis.SpeechSynthesizer]::new()
$speech.Rate = 5
foreach($SpeechString in $SpeechQueue.GetConsumingEnumerable()){
$Null = $speech.Speak($SpeechString)
}
})
$Null = $PowerShell.AddParameter('SpeechQueue',$global:SpeechQueue)
$global:SpeechHandle = $PowerShell.BeginInvoke()
}
$List = [System.Collections.Generic.List[PSObject]]::New()
}
Process {
$null = $List.Add($InputObject)
}
end {
$SpeechString = $List | Out-String
$global:SpeechQueue.Add($SpeechString)
$List | Microsoft.PowerShell.Core\Out-Default -Transcript:$($Transcript.IsPresent)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment