TTS 0 Basic Primer Reject interface Stutter--Join thread

Source: Internet
Author: User

I believe most of the people who do WPF have been worrying about the interface. Especially when WPF encounters TTS you can go back to sleep ...


On this issue, out of a few solutions, some of the treatment of small diseases, some treatment of major diseases, and some to root. Let's share it with you today.


TTS was developed by Microsoft and found a Speechvoicespeakflags class in one of its few attributes . This class encapsulates a number of playback methods, the more commonly used are svsfdefault (synchronous) and Svsflagsasync (asynchronous), the difference is that when I use synchronous execution, if the current voice list needs to be broadcast is not finished, it will not execute the subsequent program. In the asynchronous way, after the client sends out the Voice command, the next statement that broadcasts the Voice command will be executed immediately, instead of waiting until the broadcast engine has all the broadcast list read back to the client.

In this case, because many speech functions are interface-related, we can fix the problem by modifying such attributes.


But the problem is that we have more needs ~~~~~~~~~~~~~~~~


The voice broadcast is no problem. But this pause of voice worries me.

Because the playback has only one control, that is, the broadcast object to perform the pronunciation of the way is synchronized, then the end of the pause is synchronized. And I use the asynchronous way, it still has to receive my instructions and then immediately execute my back code. Cause I want to let the voice pause, always show the sound of the small broadcast is still playing the voice, repeated several times before the reaction, I can endure, I do not know what the customer heard is what feeling ~


But standing on the point of serving the right, let's kill the problem.

If the sound affects the interface, then why don't we separate the sound? It's also a good idea to have the sound open another thread and set its opening and pausing by adjusting the thread's priority.

By the way, the delegate is to pass the method we use in the form of parameters.

Okay, put a core code block on it.

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" >        //<summary>/TTS initialization        //</summary> public static void Initspeek ()        {            Thread speekthread = new Thread (delegatealarmspeek);            Speekthread.isbackground = true;            Speekthread.priority = threadpriority.lowest;//Sets the minimum level of thread            speekthread.start ();        }        public delegate void Delegatealarmspeek (object obj);        private static void Delegatealarmspeek (Object obj)        {            Delegatealarmspeek delegatealarmspeek = new Ttsmanage.delegatealarmspeek (Alarmspeek);            Delegatealarmspeek (New object ());        } </span>


The alarmspeek here is the specific broadcast method we write for pronunciation.

Someone asked, so how to control the voice loop playback it?

There are always many ways. A Alarmspeek flag can solve the while (!isstopspeek).

With this thread control, if you want your voice to stop for a while after it's played again, it'll be done in seconds. Thread.Sleep (10);


Although the examples are simple, how many points of knowledge are difficult in the project? Isn't it just a little bit of accumulation?

Of course this article is only entry-level, in-depth is still in the study. Although the benefits are many, but the use is still to be used carefully according to the specific situation, or you see due to synchronization, asynchronous, multithreading and other problems ~ Next blog to be continued ~









Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

TTS 0 Basic Primer Reject interface Stutter--Join thread

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.