wpf语音播报暂停_使用BabySmash学习WPF-语音合成
wpf語音播報暫停
NOTE: If you haven't read the first post in this series, I would encourage you do to that first, or check out the BabySmash category. Also check out http://windowsclient.net/ for more developer info on WPF.
注意:如果您還沒有閱讀本系列的第一篇文章,我建議您先閱讀該文章,或者查看BabySmash類別。 另請訪問http://windowsclient.net/以獲取有關(guān)WPF的更多開發(fā)人員信息。
BACKGROUND: This is one of a series of posts on learning WPF. I wrote an application for my 2 year old using WPF, but as I'm a Win32-minded programmer, my working app is full of Win32-isms. It's not a good example of a WPF application even though it uses the technology. I'm calling on community (that's you, Dear Reader) to blog about your solutions to different (horrible) selections of my code. You can get the code http://www.codeplex.com/babysmash. Post your solutions on your blog, in the comments, or in the Issue Tracker and we'll all learn WPF together. Pick a single line, a section, or subsystem or the whole app!
背景:這是有關(guān)學(xué)習(xí)WPF的一系列文章之一。 我使用WPF為2歲的孩子編寫了一個應(yīng)用程序,但是由于我是位Win32程序員,所以我的工作應(yīng)用程序充滿了Win32-ism。 即使它使用WPF技術(shù),也不是WPF應(yīng)用程序的好例子。 我正在呼吁社區(qū)(即您,親愛的讀者)在博客中介紹您針對我的代碼的不同(糟糕)選擇的解決方案。 您可以獲取代碼http://www.codeplex.com/babysmash 。 將您的解決方案發(fā)布到您的博客,評論或問題跟蹤器中,我們將一起學(xué)習(xí)WPF。 選擇一條線,一個部分,子系統(tǒng)或整個應(yīng)用程序!
There's been a flood of interesting content coming in around BabySmash, including WPF Expert Karl Shifflett who found the original code so nasty that he rewrote it from scratch! I'll do a whole post analyzing his code and how I can refactor my own.
BabySmash周圍到處都有大量有趣的內(nèi)容,包括WPF專家Karl Shifflett ,他發(fā)現(xiàn)原始代碼是如此討厭,以至于他從頭重寫了代碼! 我將在整篇文章中分析他的代碼以及如何重構(gòu)自己的代碼。
Before that, I wanted to share one little tidbit that isn't explicit to WPF but rather to the .NET Framework 3.0. Most folks think of .NET 3.0 (myself included) as being WPF (Windows Presentation Foundation), WCF (Windows Communication Foundation) and WF (Windows Workflow). However, there's a bunch of miscellaneous goodness in in .NET 3.0 that I always forget about.
在此之前,我想分享一個對WPF并不明確但對.NET Framework 3.0明確的提示。 大多數(shù)人認(rèn)為.NET 3.0(包括我自己)是WPF(Windows Presentation Foundation),WCF(Windows Communication Foundation)和WF(Windows Workflow)。 但是,.NET 3.0中有很多其他優(yōu)點,我總是會忘記。
In BabySmash I wanted to have the letters and shapes spoken when they appear on the screen, and lazily, rather than recording the sounds, I thought to myself, "self, why not text to speech?"
在BabySmash中,我想讓字母和形狀在屏幕上出現(xiàn)時能說出來,而且我懶洋洋地而不是錄制聲音,而是對自己說:“我自己,為什么不文本到語音?”
I know there's TTS (Text to Speech) stuff in Windows as COM Objects, so I went into Add Reference in Visual Studio, found the component and added it. A .NET wrapper got created that makes the COM object look like .NET and off I went.
我知道Windows中有TTS(文本到語音)內(nèi)容作為COM對象,因此我進(jìn)入了Visual Studio中的“添加引用”,找到了該組件并將其添加。 創(chuàng)建了一個.NET包裝器,使COM對象看起來像.NET,然后我離開了。
Turns out that .NET 3.0 includes System.Speech, an official component that does all this for me. I yanked out the COM stuff and put System.Speech in, and got the added benefit of a Cancel method to stop any current speech. This is particularly helpful for BabySmash because when kids hit the keyboard fast the speech system slowed down as words to say queued up. It couldn't say the words as fast as they were said.
事實證明.NET 3.0包含System.Speech,這是為我完成所有這些工作的官方組件。 我拉出COM組件,然后放入System.Speech,并獲得了Cancel方法來停止任何當(dāng)前語音的附加好處。 這對BabySmash尤其有用,因為當(dāng)孩子們快速按下鍵盤時,語音系統(tǒng)會因為說的單詞排隊而變慢。 它不能像說的那樣快。
objSpeech = new SpeechSynthesizer();objSpeech.SpeakAsyncCancelAll();
objSpeech.Rate = -1;
objSpeech.Volume = 100;
objSpeech.SpeakAsync(s);
//REMOVED COM STUFF
//objSpeech.WaitUntilDone(Timeout.Infinite);
//objSpeech.Speak(s, SpeechVoiceSpeakFlags.SVSFlagsAsync);
Additionally, by using the COM Component, I got into trouble where Vista has version 5.3 and XP had version 5.0. This made it difficult for developers using XP to build the program. This goes away when using the .NET assembly.
另外,通過使用COM組件,我遇到了麻煩,其中Vista的版本為5.3,而XP的版本為5.0。 這使得使用XP的開發(fā)人員難以構(gòu)建程序。 使用.NET程序集時,這種情況消失了。
Hopefully I'll get to do more "refactoring via subtraction" as I dig deeper into .NET 3.x.
希望隨著我對.NET 3.x的深入研究,能夠做更多的“減法重構(gòu)”。
Also, thanks to Gina at LifeHacker for her post on BabySmash! The comments are pretty good, but the best interaction was these two comments:
另外,還要感謝LifeHacker的Gina在BabySmash上的帖子! 這些評論非常好,但是最好的交互是這兩個評論:
"Wow, 15 years of progress with Windows and this is all we have to show for it? No wonder Windows is teh suckage."
“哇,Windows已經(jīng)有了15年的進(jìn)步,這就是我們要做的一切?難怪Windows真是吸引人。”
Very supportive! ;) And a response from another random commenter:
非常支持! ;)和另一個隨機(jī)評論者的回應(yīng):
"Wow, I've seen people take cheap shots at Windows, but this is the winner! A dad who writes a program for his son suddenly contributing to windows being 'teh suckage' ..."
“哇,我見過人們在Windows上拍便宜的照片,但這是贏家!一位父親為他的兒子寫了一個程序,突然導(dǎo)致Windows成為'吸盤'……”
Bam. Baby! Smash!
am 寶寶! 粉碎!
翻譯自: https://www.hanselman.com/blog/learning-wpf-with-babysmash-speech-synthesis
wpf語音播報暫停
總結(jié)
以上是生活随笔為你收集整理的wpf语音播报暂停_使用BabySmash学习WPF-语音合成的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Flex 开发PDF阅读器 【转】
- 下一篇: mmdetection/mmdetect