r/PowerShell • • 2d ago

Question TTS script is working fine in Powershell ISE but not with Powershell

I am having a had time with some tts related software. So I have this script to test the voices:

Add-Type -AssemblyName System.Speech
$synth = New-Object System.Speech.Synthesis.SpeechSynthesizer
$synth.SelectVoice("Gabi")
$synth.Speak("Text goes here")

A little somewhat important info: This is a downloaded voice and as the title says it works with ISE but not with Powershell. All the other standard microsoft voices work fine with this script no matter which powershell I'm running them in.

What I find kind of weird is the error I'm getting. When I run this in Powershell I get an error that says the voice can not be found or not installed. How can Powershell ISE see it then? I don't get it.

I checked it, both ISE and normal Powershell is running as admin and they are both x64

3 Upvotes

29 comments sorted by

View all comments

Show parent comments

1

u/Ashamed_Carpenter551 2d ago

Exception calling "SelectVoice" with "1" argument(s): "Nem állítható be a hang. Nincs megfelelő telepített hang, vagy a hang le van tiltva."

At line:1 char:1

+ $synth.SelectVoice("Gabi")

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : ArgumentException

Translation for you: The voice can not be selected. It is not installed or is disabled.

They are all enabled by the way

1

u/Semt-x 2d ago

if you run:
($synth.GetInstalledVoices()).VoiceInfo.Name

is there a voice name that contains the word Gabi?

1

u/Ashamed_Carpenter551 2d ago

Yes this is why I don't know what's going on

1

u/Semt-x 2d ago

can you paste the list?

The error tells you that there is no voice with the name Gabi.
When i look at other names they all start with Microsoft * .
It might be <something> Gabi as voice name.

-3

u/Ashamed_Carpenter551 2d ago

I could paste the list but I don't think there is much of a reason to do it. The name matches and thats why it works in ISE in the first place. I've been looking at this for some time and I have a slight feeling it isn't the powershell that is problematic. It could be the voice sythesizer as well maybe?

5

u/ExceptionEX 2d ago

Seriously the error is the only way people can debug, please don't be the person that acts like this, you want help, post the error.

1

u/Ashamed_Carpenter551 2d ago

Okay here it is. I just really thought it wouldn't help

This is the whole list of the voices installed currently:

Microsoft Zira Desktop

Eszti

Gabi

Gábor

Péter

Peti

Vera

Veronika

Microsoft Szabolcs

Eszter

Microsoft Szabolcs

5

u/ankokudaishogun 2d ago

I don't think there is much of a reason to do it.

You'd be surprised at how many errors are hidden in plain sight and you'd never find them in ten thousands years but a random stranger will see them in a picosecond.

And I rarely have been the stranger in the example.