Powershell: Text To Speech in 3 lines of code

There are times where small and simple things can have big impact for a larger audience, one example is implementing a Text To Speech function. Users want to interact with machines in a smarter and meaningful way, the biggest challenge is for developers and engineers to meet that expectation integrating those features in their solutions.

We always give for granted that notifications are visual and users are always staring in front of a monitor waiting for a pop-up window or a new line on the cli to check progress or output of a repetitive operation.
But I think that in many cases text to speech is a good way getting user attention or providing useful instructions. So let’s dive into..

PowerShell Text To Speech

Let’s start with a PowerShell example:

As we all know, Powershell is built on top of .NET Framework, so we can directly point to a class such System.Speech.Syntesis.SpeechSynthesizer .

Looking at the object’s properties we can modify:

  • Rate (speed /speaking rate)
  • State ( status of the SpeechSynthesizer)
  • Voice (Change voice gender/ culture/ etc..)
  • Volume (Volume of the SpeechSynthesizer).

To start from the beginning, we need a direct reference to the .NET Object

Let’s check the new object created:

This will be the output :

Now, let’s check the voice used:

List all the installed voice

With this result:

How to change/select the voice

If I want to change my voice with a Female voice:

As usual, you can find the source code and these examples on my GitHub repository.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.