Text-To-Speech issue in Windows Server 2016 task scheduler

Dismas 1 Reputation point
2020-10-05T14:16:07.357+00:00

Hello,

I encounter the following issue in task scheduler with a powershell script that use text-to-speech to produce a wave file.

The Powershell script is :

$logfile = New-Item -Path "C:\TEST" -Name "SPEECH_$(Get-Date -Format yyyyMMdd_HHmm)_$($env:COMPUTERNAME).log" -ItemType File -Force
$wavfile = New-Item -Path "C:\log" -Name "SPEECH_$(Get-Date -Format yyyyMMdd_HHmm)_$($env:COMPUTERNAME).wav" -ItemType File -Force
"------------------------------------------------------------------------------------------------" | Out-File -FilePath $logfile -Encoding utf8
Add-Type -AssemblyName System.Speech
$speak  = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speak.SetOutputToWaveFile($wavfile)
$speak.GetInstalledVoices().VoiceInfo | Out-File -FilePath $logfile -Encoding utf8 -Append
$speak.SelectVoice('Microsoft Hortense Desktop')
$speak.Voice | Out-File -FilePath $logfile -Encoding utf8 -Append
$speak.speak("Bonjour, ceci est un test.")
$speak.Dispose()

When running manually, the log file shows 2 installed voices Microsoft Hortense Desktop and Microsoft Zira Desktop respectively fr-Fr and en-US and I can confirm that the selected voice is Microsoft Hortense Desktop.

When running in task scheduler, the log shows the same 2 installed voices but the selected voice is Microsoft Zira Desktop as if Microsoft Hortense Desktop was ignored.

I can't explain why this issue. Is there something wrong with task scheduler ?

Regards.

Edit : I know it as something to do with the user account running the scheduled task. If running as a local or domain user, it fails to select the fr-FR voice. If running as the SYSTEM account it is working !
Edit 2 : The local or domain user is member of the Administrators group and the task is set to run with the highest priviledges.
Edit 3 : Nearly same behaviour with the nircmd tool with command nircmd speak text "Bonjour, ceci est un test." 0 100 C:\log\nircmd.wav 48kHz16BitStereo. The difference is the task produce a corrupt wave file of 1 kb as if the tool cannot switch to the fallback en-US voice
Edit 4 : In fact, the task cannot use the default fr-FR voice if it is not set to "run only when user is logged on". Even when the output is redirected to a wave file. The only exception is the SYSTEM account which is already logged... Strange !

Windows for business Windows Server User experience Other
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.