How to use PowerShell Speech commands

Did you know that PowerShell has built in commands for speech? This mean that you can get PowerShell to read your commands or results of commands.

How to use PowerShell Speech commands

I recently came across an interesting blogpost about speech commands in PowerShell. I was not aware that PowerShell had built-in commands for Speech, but it has. It is not easy to find much official documentation about it, but I will show you some small examples to get started.

Getting started with PowerShell Speech

At first, we will need to setup the basic and select the voice we want to read up for us. In this example I have chosen the build in female voice named Zira.

Add-Type -AssemblyName System.Speech
$Speech = New-Object System.Speech.Synthesis.SpeechSynthesizer
$Speech.SelectVoice(“Microsoft Zira Desktop”)

Now we got the basic covered and now we are ready to give Zira some commands to read up loud.

$message = (Get-Date).ToShortTimeString()
$message = $message.ToString()
$Speech.speak(“The current time is” + $message)
$Speech.speak(“User logged in is ” + $env:USERNAME)
$Speech.speak(“Computername is ” + $env:computername)

Set Volume level

If you want to control the volume of the speech, you can set the volume level between 0-100 with the command below:

$Speech.Volume = 50

Show available Voices installed

In Windows 10 (US version) there is two default voices to choose. If you have another language of Windows, you might have other voices to choose from. If you install e.g. the German language pack to Windows 10, you will get a voice named Hedda. To see a list of installed voices, execute the command line below:

$speech.GetInstalledVoices() | Select-Object -ExpandProperty VoiceInfo | Select-Object -Property Culture, Name, Gender, Age

Change reading speed

It is also possible to change the speed that PowerShell reads with. Try changing the speed to 7 like the example below. This will speed up the reading rate. The rate can be any value between -10 through 10:

$Speech.Rate = 7

More Speech commands

To see the full list of Voice commands, enter the following command:

$Speech | Get-Member

Now it is your time

I have now learned you the basic skills to get started with PowerShell Speech. Now you can move on an make your own small scripts to read messages up loud.  Maybe you can make PowerShell read the weather forecast for you or maybe you can ask PowerShell for the current CPU temperature. Only your imagination is the limit 🙂 Feel free to drop me a comment or ask a question below.

If you, like me, love PowerShell, you should go and visit my little PowerShell World at blogger

 

 

Thomas
About the author:
I am an IT Professional that has this blog as a hobby project in my spare time. I have been in the IT business since 1996 and want to share some of the thing I have picked up over the years, with people who visit this blog.

>>Subscribe to my Newsletter<<

Related posts

Leave a Comment