top of page
  • Writer's pictureshishir kushawaha

PowerShell can 'SPEAK()' too!

Small and simple changes can sometimes have a significant impact on a large audience. One such example is the integration of a Text-to-Speech function. People desire a smarter and more meaningful interaction with machines, and it is the responsibility of developers and engineers to fulfill this need by incorporating such features into their creations.

We tend to assume that notifications are visual and that users are always closely observing their screens for pop-up windows or updates in the command-line interface during repetitive operations. However, in many cases, using text-to-speech to draw attention or provide clear instructions can prove to be a useful solution. Let's delve into this further...


Here's a sample PowerShell script that can be used to convert text into speech using the System.Speech.Synthesis namespace:

# Import the System.Speech.Synthesis namespace
Add-Type -AssemblyName System.Speech

# Set the text to be spoken
$text = "Hello, I am a PowerShell script that converts text into speech."

# Create a new instance of the SpeechSynthesizer class
$speechSynthesizer = New-Object System.Speech.Synthesis.SpeechSynthesizer

# Speak the text
$speechSynthesizer.Speak($text)

This script adds the System.Speech.Synthesis namespace and creates a new instance of the SpeechSynthesizer class. Then, it uses the Speak() method to convert the text into speech.

Please note that this script requires that you have the Text-to-Speech feature installed on your machine.

Here are a few additional details that might help you understand the script better:

  1. The Add-Type cmdlet is used to import the System.Speech.Synthesis namespace, which provides the functionality to convert text into speech.

  2. The $text variable is used to store the text that you want to convert into speech. You can change the text to anything you want.

  3. The New-Object cmdlet is used to create a new instance of the SpeechSynthesizer class. This class is part of the System.Speech.Synthesis namespace and provides the functionality to convert text into speech.

  4. The $speechSynthesizer.Speak($text) line is used to convert the text into speech. The Speak() method takes a string as an argument and converts it into speech.

You can also change the voice and volume of the speech output by modifying the properties of the SpeechSynthesizer object. For example:

# Set the voice of the speech synthesizer
$speechSynthesizer.SelectVoice("Microsoft Zira Desktop")

# Set the volume of the speech synthesizer
$speechSynthesizer.Volume = 100

This sets the voice of the speech synthesizer to "Microsoft Zira Desktop" and sets the volume to 100 (the maximum value).

In addition to these methods and properties, the SpeechSynthesizer class also provides other methods and properties that you can use to customize the speech output further. You can find more information on the .NET Framework documentation website: https://docs.microsoft.com/en-us/dotnet/api/system.speech.synthesis.speechsynthesizer


502 views0 comments

Recent Posts

See All

PowerShell to search specific file in entire disk

Is there a way to utilize Windows PowerShell to search for a file that I saved somewhere on my computer but cannot locate? Is there a method to locate a file throughout the entire disk and remove it a

bottom of page