Hi,
Windows has a builtin feature to convert text to speech and play it over the speakers. This can be used in powershell by using the System.Speech namespace.
First of all include the namespace
PS D:\> Add-Type -AssemblyName System.Speech
Then create an instance of the SpeechSynthesizer class
PS D:\> $SpeechEngine = New-Object System.Speech.Synthesis.SpeechSynthesizer
Make a first test
PS D:\> $SpeechEngine.Speak("Passt schon")
Get all installed language details
PS D:\> $SpeechEngine.GetInstalledVoices() | Select-Object -ExpandProperty VoiceInfo Gender : Male Age : Adult Name : Microsoft David Desktop Culture : en-US Id : TTS_MS_EN-US_DAVID_11.0 Description : Microsoft David Desktop - English (United States) SupportedAudioFormats : {} AdditionalInfo : {[Age, Adult], [Gender, Male], [Language, 409], [Name, Microsoft David Desktop]...} Gender : Female Age : Adult Name : Microsoft Zira Desktop Culture : en-US Id : TTS_MS_EN-US_ZIRA_11.0 Description : Microsoft Zira Desktop - English (United States) SupportedAudioFormats : {} AdditionalInfo : {[Age, Adult], [Gender, Female] , [Language, 409], [Name, Microsoft Zira Desktop]...}
Select the voice which fits your needs (must be supported bei the installed language)
PS D:\> [System.enum]::GetNames([System.Speech.Synthesis.VoiceGender]) NotSet Male Female Neutral
PS D:\> [System.enum]::GetNames([System.Speech.Synthesis.VoiceAge]) NotSet Child Teen Adult Senior
Set the output details
PS D:\> $SpeechEngine.SelectVoiceByHints([System.Speech.Synthesis.VoiceGender]::Female,[System.Speech.Synthesis.VoiceAge]::Adult,1,"en-US")
Show whats set
PS D:\> $SpeechEngine.voice Gender : Female Age : Adult Name : Microsoft Zira Desktop Culture : en-US Id : TTS_MS_EN-US_ZIRA_11.0 Description : Microsoft Zira Desktop - English (United States) SupportedAudioFormats : {} AdditionalInfo : {[Age, Adult], [Gender, Female], [Language, 409], [Name, Microsoft Zira Desktop]...}
Additional languages can be installed by download the Language pack DVD. For example german
PS D:\> Dism /online /Add-Capability /capabilityname:Language.Speech~~~de-de~0.0.1.0 /source:D:\LanguagesAndOptionalFeatures PS D:\> Dism /online /Add-Capability /capabilityname:Language.TextToSpeech~~~de-de~0.0.1.0 /source:D:\LanguagesAndOptionalFeatures
Or from the Microsoft store.
Michael