Skip to content

Instantly share code, notes, and snippets.

@hoang-himself
Created August 19, 2022 05:11
Show Gist options
  • Save hoang-himself/ba5ff87479093a55c008c3de0d443e38 to your computer and use it in GitHub Desktop.
Save hoang-himself/ba5ff87479093a55c008c3de0d443e38 to your computer and use it in GitHub Desktop.
PowerShell 7 speech syntheziser
function Sing99Bottles {
$total = 99
Add-Type -AssemblyName System.speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speak.selectvoice('Microsoft Zira Desktop')
$speak.rate = 4
1..100 | ForEach-Object {
$Words = "$total bottles of beer on the wall, $total bottles of beer. Take one down and pass it around, $($total - 1) bottles of beer on the wall."
$speak.Speak($Words)
$total = $($total - 1)
}
}
function Sing99BottlesAdvanced {
Add-Type -AssemblyName System.speech
$speech = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speech.selectvoice('Microsoft Zira Desktop')
$speech.rate = 3
foreach ($total in 99..1) {
$words = '{0} bottle{2} of beer on the wall, {0} bottle{2} of beer. Take one down and pass it around, {3} bottle{4} of beer on the wall.' -f $total, ($total - 1), @{$true = 's'; $false = '' }[$total -ne 1], @{$true = 'no more'; $false = $total - 1 }[$total -eq 1], @{$true = 's'; $false = '' }[$total -ne 2]
$speech.Speak($words)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment