0

Speech Synthesis fails to SetVoice(). All are listed as enabled, until it's tried, then fails with the non-default two listed as 'disabled'.

NOTE: This works on a WPF or Console app, but fails as an ASP.NET app. ALSO: Speech is created on an alternate thread (Task.Run(()=>StartSpeech()) since it permanently locks the main thread for ASP.NET applications (see No response to a HTTP Get request in WebAPI in .NET 4.5 while using SpeechSynthesis for converting text to speech for details). However, the SelectVoice() fails on both the alternate thread as well as the main.

Ideas?

        private SpeechSynthesizer speech; //System.Speech.Synthesis
        var voices = speech.GetInstalledVoices();
        //[0]: "Microsoft David Desktop" ["Enabled"]
        //[1]: "IVONA 2 Emma" ["Enabled"]
        //[2]: "Microsoft Zira Desktop" ["Enabled"]

        try
        {
            speech.SelectVoice( "Microsoft Zira Desktop" );
        }
        catch (Exception e)
        {
            var p = e; //fails (System.ArgumentException: Cannot set voice. No matching voice is installed or the voice was disabled)
        }

        voices = speech.GetInstalledVoices();
        //[0]: "Microsoft David Desktop" ["Disabled"]
        //[1]: "IVONA 2 Emma" ["Enabled"]
        //[2]: "Microsoft Zira Desktop" ["Disabled"]

        speech.SpeakAsync( text );
Community
  • 1
  • 1
Jim
  • 804
  • 6
  • 17

1 Answers1

0

Turns out, this even worked under Visual Studio IIS Express, but failed under IIS. Switching from ApplicationPoolIdentity to LocalSystem made it work. Seems like SelectVoice() is a rights-enabled call where simply speaking isn't.

Answer: Change Application Pool's Identity (in IIS) to LocalSystem.

Jim
  • 804
  • 6
  • 17