8 Replies - 710 Views - Last Post: 17 October 2016 - 06:04 PM Rate Topic: -----

#1 viktor80  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 25-April 16

System.PlatformNotSupportedException with TTS on Splash Screen

Posted 17 October 2016 - 05:30 AM

Hello,

I use
System.Speech.Synthesis;
Text-to-Speech with female voice. It worked perfectly without any problem, until I add Splash Screen, which contains only progress bar and background image, nothing special. And now after splash screen is finished, I have this:


An unhandled exception of type 'System.PlatformNotSupportedException'
occurred in System.Speech.dll


and it happens not every time. Sometimes program is loaded, and sometimes exception points to this line:

sSynth.SelectVoiceByHints(VoiceGender.Female);


Without Splash Screen works well as usually, or enough just to remove this line and it works again. Now I'm trying to catch it with catch (Exception ex) but so far it is not repeated, will see... Seems like, something is wrong with Splash Screen, I guess. Before I finally go on to WPF, I want to finish my WinForm application too, so can you help figure out with this problem, what it can be, what is wrong?

Splash screen contains only:

  private void timer1_Tick(object sender, EventArgs e)
            {
                progressBar1.ForeColor = Color.Blue; 
                progressBar1.BackColor = Color.FromArgb(0, 204, 211);  
                progressBar1.Increment(1);  
                if (progressBar1.Value == 100)  
                timer1.Stop();  
            }


and in Program.cs this line is commented:

 Application.EnableVisualStyles();


to be able to change color for progress bar. And Splash Screen lines in Form1.cs with `sSynth.SelectVoiceByHints(VoiceGender.Female);` which is also is there, is:

public Form1()
            {
                Thread t = new Thread(new ThreadStart(SplashStart));
                t.Start(); 
                Thread.Sleep(5000); 
    
                InitializeComponent();
    
                t.Abort(); 
              
                sSynth.SelectVoiceByHints(VoiceGender.Female); 
            }

     public void SplashStart() 
            {
                Application.Run(new Form2());
            }


This post has been edited by viktor80: 17 October 2016 - 05:41 AM


Is This A Good Question/Topic? 0
  • +

Replies To: System.PlatformNotSupportedException with TTS on Splash Screen

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5899
  • View blog
  • Posts: 20,142
  • Joined: 05-May 12

Re: System.PlatformNotSupportedException with TTS on Splash Screen

Posted 17 October 2016 - 06:12 AM

That is not the right way to do a splash screen in WinForms. The correct way to do it is to change the active from in the ApplicationContext. You are essentially invoking undefined behavior when your main entry point calls Application.Run() passing in your Form1, and then you fire up another thread and call Application.Run() passing in your Form2.

See here: Use the ApplicationContext Class to Fully Encapsulate Splash Screen Functionality
Was This Post Helpful? 1
  • +
  • -

#3 viktor80  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 25-April 16

Re: System.PlatformNotSupportedException with TTS on Splash Screen

Posted 17 October 2016 - 08:56 AM

Hello,

Thanks for this, also I want to ask, if variant above is wrong one, can you also look at this, what you think, before I going to follow your advice. Without any progress bar, and code inside main code, I just need it to fill short interval of time when loading, I hope this variant should not make the same exception:

Splash Screen code:

public Form2()
        {
            InitializeComponent();

            timer1.Enabled = true;
            timer1.Interval = 3000;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Stop();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }



and Program.cs:

 static void Main()
        {
            Application.EnableVisualStyles(); 
            Application.SetCompatibleTextRenderingDefault(false);
            Form2 sp = new Form2();

            if (sp.ShowDialog() == DialogResult.OK)
            {
                Application.Run(new Form1());
            }
        }

This post has been edited by viktor80: 17 October 2016 - 09:03 AM

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5899
  • View blog
  • Posts: 20,142
  • Joined: 05-May 12

Re: System.PlatformNotSupportedException with TTS on Splash Screen

Posted 17 October 2016 - 09:45 AM

That should work assuming that timer messages are pumped while showing a dialog. (The should be in WinForms.)

I don't see the point, though. All you did was delay starting your program. The point of a splash screen is to distract the user from the fact that it is taking a long time to start up your program. It's not meant to be an advertising platform, a vanity page, or a EULA confirmation.
Was This Post Helpful? 0
  • +
  • -

#5 viktor80  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 25-April 16

Re: System.PlatformNotSupportedException with TTS on Splash Screen

Posted 17 October 2016 - 04:47 PM

yes I want use it exactly for this reason, but seems like problem is something else. And have no idea how to where to move. here is cached message, with both variant and now with yours too. So it's look like something is wrong, maybe with last windows update, several days ago. And now have no idea how to figure out:

No voice installed on this system or none available with current security setting
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5899
  • View blog
  • Posts: 20,142
  • Joined: 05-May 12

Re: System.PlatformNotSupportedException with TTS on Splash Screen

Posted 17 October 2016 - 04:54 PM

By any chance is you AV software kicking in each time your program is run? For example, the latest version of Avast keeps scanning and sandboxing my code unless I specifically tell it to trust my code.
Was This Post Helpful? 0
  • +
  • -

#7 viktor80  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 25-April 16

Re: System.PlatformNotSupportedException with TTS on Splash Screen

Posted 17 October 2016 - 05:08 PM

I have only Windows Defender and it was ok all this time with it, just now I turned it off, but got same message, so seems like problem with something else.

This post has been edited by viktor80: 17 October 2016 - 05:08 PM

Was This Post Helpful? 0
  • +
  • -

#8 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5899
  • View blog
  • Posts: 20,142
  • Joined: 05-May 12

Re: System.PlatformNotSupportedException with TTS on Splash Screen

Posted 17 October 2016 - 05:29 PM

Well, at this point, the only difference between working code, and non-working code should be the line that SelectVoiceByHints(), unless you are holding back something and your splash screen actually does more stuff than just wait.
Was This Post Helpful? 0
  • +
  • -

#9 viktor80  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 25-April 16

Re: System.PlatformNotSupportedException with TTS on Splash Screen

Posted 17 October 2016 - 06:04 PM

now I'm checking my previous version without Splash Screen, I guess there is no any connection with this problem, but directly with Speech Synthesis, and not only with female voice line, if I remove it then it point on other Speech Synthesis line etc,.

Here it says:

It could be caused by following reasons:

1. The speech platform runtime is installed, but the language pack is not installed. Make sure you install the TTS language pack.

2. The speech platform and language pack are installed, but the .net application is compiled as a target platform different from the speech platform. For example, speech platform is x64, but the app is x86.


I download here this file MSSpeech_SR_en-US_TELE and now I'm trying to install it, but the installer stops on halfway and installation does not occur, have no idea why, but at the same time I don't understand, how it can be "not installed" if all this time I use it in References just with System.Speech and also if I reboot the Visual Studio sometimes it works and then again broken. And same I can say about reason number two, if it was ok, and periodically works, if that reason it should not work continuously, right?

This post has been edited by viktor80: 17 October 2016 - 06:09 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1