Console Speech API, Part 2

19 Apr, 2023

In my last post, Console Speech API and Beeps, I talked about the text to speech .NET assembly and how to get your computer to talk to you. After some searching I remembered I wrote a game in PowerShell similar to my Python based game. This was a simple way to help teach children letters and the keyboard.

Add-Type -AssemblyName System.Speech
$Speech = New-Object System.Speech.Synthesis.SpeechSynthesizer
$Alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.ToCharArray() -as [string[]]

while($true) {
    $Letter = $Alphabet[(Get-Random -Minimum 0 -Maximum $Alphabet.Count)]
    $Assignment = "Press the letter, $Letter"
    $Answer = Read-Host -Prompt $Assignment
    if ($Answer.Length -gt 0) {
        if ($Letter -eq $Answer) {
            $Speech.Speak("Correct! You pressed the letter, $Answer.")
        } elseif ($Answer -in $Alphabet) {
            $Speech.Speak("Incorrect. You should have pressed, $Letter, but you pressed, $Answer.")
        } else {
            $Speech.Speak("That was not a letter.")
    } else {
        $Speech.Speak("You did not press anything.")

Check out the source in my PowerShell Snippets.

I'm publishing this as part of 100 Days To Offload. You can join in yourself by visiting

Tags: powershell, 100DaysToOffload


If there are replies, they will show below.

2 Likes 1 Repost

Found an issue? Edit on Github

← Back home