private void btnSayHello_Click(object sender, RoutedEventArgs e) { PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("Hello world"); PromptStyle promptStyle = new PromptStyle(); promptStyle.Volume = PromptVolume.Soft; promptStyle.Rate = PromptRate.Slow; promptBuilder.StartStyle(promptStyle); promptBuilder.AppendText("and hello to the universe too."); promptBuilder.EndStyle(); promptBuilder.AppendText("On this day, "); promptBuilder.AppendTextWithHint(DateTime.Now.ToShortDateString(), SayAs.Date); promptBuilder.AppendText(", we're gathered here to learn"); promptBuilder.AppendText("all", PromptEmphasis.Strong); promptBuilder.AppendText("about"); promptBuilder.AppendTextWithHint("WPF", SayAs.SpellOut); SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); speechSynthesizer.Speak(promptBuilder); }
// Called when click on any chess square object private void Squar_Click(object sender, System.EventArgs e) { if (m_ParentGame.IsRunning && !m_ParentGame.ChessGame.ActivePlay.IsComputer()) { Squar ChessSquar = (Squar)sender; // m_ParentGame.Sounds.PlayClick(); style.AppendTextWithHint(ChessSquar.Name, SayAs.SpellOut); sSynth.Speak(style); // audio output coordinates of clicked empty square style.ClearContent(); m_ParentGame.SelectedSquar = ChessSquar.Name; m_ParentGame.RedrawBoard(); } }
/// <summary> /// 有日期和时间两部分。请留意返回值。过程先尝试去解释日期时间串,然后再分开加入。这样的串可以是 "2021-12-1 14:23" 也可以是 "12/1/2021 14:23" 或者其他欧美国家熟悉的时间表示法。 /// </summary> /// <param name="builder"></param> /// <param name="textToAdd"></param> /// <returns></returns> public static bool Add_As_DateTime_Text(ref PromptBuilder builder, string textToAdd) { DateTime dt; if (!DateTime.TryParse(textToAdd, out dt)) { return(false); } string sDate = dt.ToString("yyyy-M-d"); string sTime = dt.ToString("H:m"); builder.AppendTextWithHint(sDate, System.Speech.Synthesis.SayAs.YearMonthDay); builder.AppendTextWithHint(sTime, System.Speech.Synthesis.SayAs.Time24); return(true); }
private static void Testing_AppendTextWithHint() { var builder = new PromptBuilder(); builder.AppendTextWithHint("3rd", SayAs.NumberOrdinal); builder.AppendBreak(); builder.AppendTextWithHint("3rd", SayAs.NumberCardinal); builder.AppendBreak(); builder.AppendBookmark("First bookmark"); builder.AppendBreak(); builder.AppendTextWithPronunciation("DuBois", "duˈbwɑ"); builder.AppendBreak(); synthesizer.Speak(builder); }
private void SpeakEndOfGameInfo(bool isNewHighscore) { PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.StartStyle(new PromptStyle() { Emphasis = PromptEmphasis.Reduced, Rate = PromptRate.Slow, Volume = PromptVolume.ExtraLoud }); promptBuilder.AppendText("Game Over"); promptBuilder.EndStyle(); if (isNewHighscore) { promptBuilder.AppendBreak(TimeSpan.FromMilliseconds(500)); promptBuilder.StartStyle(new PromptStyle() { Emphasis = PromptEmphasis.Moderate, Rate = PromptRate.Medium, Volume = PromptVolume.Medium }); promptBuilder.AppendText("new high score:"); promptBuilder.AppendBreak(TimeSpan.FromMilliseconds(200)); promptBuilder.AppendTextWithHint(CurrentScore.ToString(), SayAs.NumberCardinal); promptBuilder.EndStyle(); } SpeechSynthesizer.SpeakAsync(promptBuilder); }
public void StartSpeech(string text, bool value, VoiceGender type) { if (value == true) { PromptBuilder promptBuilder = new PromptBuilder(); PromptStyle promptStyle = new PromptStyle(); promptStyle.Volume = PromptVolume.Soft; promptStyle.Rate = PromptRate.Slow; promptStyle.Emphasis = PromptEmphasis.Moderate; promptBuilder.StartStyle(promptStyle); promptBuilder.EndStyle(); promptBuilder.AppendTextWithHint(text, SayAs.SpellOut); SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); speechSynthesizer.SelectVoiceByHints(type); speechSynthesizer.Speak(promptBuilder); } else { PromptBuilder promptBuilder = new PromptBuilder(); PromptStyle promptStyle = new PromptStyle(); promptStyle.Volume = PromptVolume.Soft; promptStyle.Rate = PromptRate.Slow; promptStyle.Emphasis = PromptEmphasis.Moderate; promptBuilder.StartStyle(promptStyle); promptBuilder.EndStyle(); promptBuilder.AppendText(text); SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); speechSynthesizer.SelectVoiceByHints(type); speechSynthesizer.Speak(promptBuilder); } }
private void startListenning_Click(object sender, RoutedEventArgs e) { PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("My name is ALFRED"); PromptStyle promptStyle = new PromptStyle(); promptStyle.Volume = PromptVolume.Soft; promptStyle.Rate = PromptRate.Slow; promptBuilder.StartStyle(promptStyle); promptBuilder.AppendText("and I am pleased to meet you."); promptBuilder.EndStyle(); promptBuilder.AppendText("Date: "); promptBuilder.AppendTextWithHint(DateTime.Now.ToShortDateString(), SayAs.Date); promptBuilder.AppendText("Now, I would like to tell you what you wrote"); promptBuilder.AppendText("Ehm", PromptEmphasis.Strong); promptBuilder.AppendText(content.Text); SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); speechSynthesizer.Speak(promptBuilder); }
static void Main(string[] args) { var synth = new SpeechSynthesizer(); synth.SetOutputToDefaultAudioDevice(); var cultureTag = ConfigurationManager.AppSettings["culture"]; var culture = CultureInfo.GetCultureInfoByIetfLanguageTag(cultureTag); var prompt = new PromptBuilder(culture); prompt.StartSentence(culture); prompt.AppendTextWithHint(SpeakResources.Welcome, SayAs.Text); prompt.EndSentence(); synth.SpeakAsync(prompt); var recog = new SpeechRecognitionEngine(culture); recog.LoadGrammar(new DictationGrammar()); recog.SetInputToDefaultAudioDevice(); recog.SpeechRecognized += Recog_SpeechRecognized; recog.RecognizeAsync(RecognizeMode.Multiple); Console.WriteLine("Hello!"); Console.ReadLine(); synth.Dispose(); recog.Dispose(); }
static void Main(string[] args) { //Original Code from: http://www.wpf-tutorial.com/audio-video/speech-synthesis-making-wpf-talk/ PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("Hello world"); PromptStyle promptStyle = new PromptStyle(); promptStyle.Volume = PromptVolume.Soft; promptStyle.Rate = PromptRate.Slow; promptBuilder.StartStyle(promptStyle); promptBuilder.AppendText("and hello to the universe too."); promptBuilder.EndStyle(); promptBuilder.AppendText("On this day, "); promptBuilder.AppendTextWithHint(DateTime.Now.ToShortDateString(), SayAs.Date); promptBuilder.AppendText(", we're gathered here to learn"); promptBuilder.AppendText("all", PromptEmphasis.Strong); promptBuilder.AppendText("about"); promptBuilder.AppendTextWithHint("C Sharp", SayAs.SpellOut); SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); speechSynthesizer.Speak(promptBuilder); SpeechSynthesizer synth = new SpeechSynthesizer(); // Configure the audio output. synth.SetOutputToWaveFile(@"C:\temp\test.wav"); // Select the US English voice. synth.SelectVoice("Microsoft Server Speech Text to Speech Voice (en-US, Helen)"); // Build a prompt. PromptBuilder builder = new PromptBuilder(); builder.AppendText("That is a big pizza!"); // Speak the prompt. synth.Speak(builder); }
private void Speak(string text, SayAs mode = SayAs.Text) { var prompt = new PromptBuilder(culture); prompt.StartSentence(culture); prompt.AppendTextWithHint(text, mode); prompt.EndSentence(); synthesizer.SpeakAsync(prompt); }
/// <summary> /// Speaks synchronously, be award because you program will be blocked during the talk. /// </summary> /// <param name="message">Message to speak.</param> /// <param name="sayAs">Type of pronunciation</param> public void Speak(string message, SayAs sayAs = SayAs.Text) { if (_enabled && (_voices.Count > 0)) { StopSpeak(); PromptBuilder builder = new PromptBuilder(CultureInfo.CreateSpecificCulture(_culture)); builder.AppendTextWithHint(message, sayAs); _speechSynth.Speak(builder); } }
// returns board square for the given name private Squar GetBoardSquar(string strCellName) { style.AppendTextWithHint(strCellName, SayAs.SpellOut); // speak out selected square coordinates sSynth.SpeakAsync(style); style.ClearContent(); foreach (Squar ChessSquar in Squars) { if (ChessSquar.Name == strCellName) { return(ChessSquar); } } return(null); }
private void EndGame() { MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.Open(new Uri("cry.wav", UriKind.RelativeOrAbsolute)); mediaPlayer.Play(); //判断是否为新高分 bool isNewHighscore = false; if (currentScore > 0) { //高分榜中的最低分 int lowestHighscore = HighscoreList.Count > 0 ? HighscoreList.Min(x => x.Score) : 0; //如果分数大于高分榜中的最低分,或者高分榜中的记录数量还不超过最大值 //显示添加新高分的界面 if ((currentScore > lowestHighscore) || (HighscoreList.Count < MaxHighscoreListEntryCount)) { bdrNewHighscore.Visibility = Visibility.Visible; txtPlayerName.Focus(); isNewHighscore = true; //让游戏停下来 isGameRuning = false; //恭喜你,进入了高分榜 PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("恭喜你,进入了高分榜"); promptBuilder.AppendTextWithHint(currentScore.ToString(), SayAs.NumberCardinal); promptBuilder.AppendText("分"); speechSynthesizer.SpeakAsync(promptBuilder); } } //如果不是新高分,则显示成绩 if (isNewHighscore == false) { tbFinalScore.Text = currentScore.ToString(); bdrEndOfGame.Visibility = Visibility.Visible; PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("你的得分:"); promptBuilder.AppendTextWithHint(currentScore.ToString(), SayAs.NumberCardinal); promptBuilder.AppendText("分"); speechSynthesizer.SpeakAsync(promptBuilder); } gameTickTimer.IsEnabled = false; }
public void Speak(string message, SayAs sayAs = SayAs.Text) { if (voices.Count > 0) { StopSpeak(); PromptBuilder builder = new PromptBuilder(CultureInfo.CreateSpecificCulture("en-US")); builder.AppendTextWithHint(message, sayAs); speechSynth.Speak(builder); } else { Initialize(); } }
public Window1() { InitializeComponent(); SpeechSynthesizer synthesizer = new SpeechSynthesizer(); PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendTextWithHint("WPF", SayAs.SpellOut); promptBuilder.AppendText("sounds better than WPF."); // Pause for 2 seconds promptBuilder.AppendBreak(new TimeSpan(0, 0, 2)); promptBuilder.AppendText("The time is"); promptBuilder.AppendTextWithHint(DateTime.Now.ToString("hh:mm"), SayAs.Time); // Pause for 2 seconds promptBuilder.AppendBreak(new TimeSpan(0, 0, 2)); promptBuilder.AppendText("Hey Sam, can you spell queue?"); promptBuilder.StartVoice("Microsoft Sam"); promptBuilder.AppendTextWithHint("queue", SayAs.SpellOut); promptBuilder.EndVoice(); promptBuilder.AppendText("Do it faster!"); promptBuilder.StartVoice("Microsoft Sam"); promptBuilder.StartStyle(new PromptStyle(PromptRate.ExtraFast)); promptBuilder.AppendTextWithHint("queue", SayAs.SpellOut); promptBuilder.EndStyle(); promptBuilder.EndVoice(); // Speak all the content in the PromptBuilder synthesizer.SpeakAsync(promptBuilder); }
private void EndGame() { // 判断 是否为新高分 Boolean isNewHighScore = false; if (currentScore > 0) { int lowestHightScore = HighScoreList.Count > 0 ? HighScoreList.Min(x => x.Score) : 0; if ((currentScore > lowestHightScore) || (HighScoreList.Count < MaxHighScoreListEntryCount)) { // 胜利的叫声 mediaPlayer.Open(new Uri("Musics/win.wav", UriKind.RelativeOrAbsolute)); mediaPlayer.Play(); bdrNewHighScore.Visibility = Visibility.Visible; this.txtPlayerName.Focus(); isNewHighScore = true; PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("恭喜你,进入了高分榜,你的得分是:"); promptBuilder.AppendTextWithHint(currentScore.ToString(), SayAs.NumberCardinal); promptBuilder.AppendText("分"); speechSynthesizer.SpeakAsync(promptBuilder); } } if (isNewHighScore == false) { // 没有进入高分榜的惨叫声 mediaPlayer.Open(new Uri("Musics/win.wav", UriKind.RelativeOrAbsolute)); mediaPlayer.Play(); this.tbFinalScore.Text = currentScore.ToString(); this.bdrEndOfGame.Visibility = Visibility.Visible; PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("对不起,你没有进入高分榜,你的得分是:"); promptBuilder.AppendTextWithHint(currentScore.ToString(), SayAs.NumberCardinal); promptBuilder.AppendText("分"); speechSynthesizer.SpeakAsync(promptBuilder); } gameTickTimer.IsEnabled = false; // 停止定时器 isFlagStart = false; isCanAgein = true; }
public void Say() { if (_text == null) { return; } using (var sp = new SpeechSynthesizer()) { var p = new PromptBuilder(); p.StartSentence(); p.StartStyle(new PromptStyle(PromptRate.Slow)); p.AppendBreak(PromptBreak.Small); p.AppendTextWithHint(new string(_text), SayAs.SpellOut); p.EndStyle(); p.EndSentence(); sp.Speak(p); p.ClearContent(); } }
public void SpeakAsync(string message, SayAs sayAs = SayAs.Text) { if (_enabled && (_voices.Count > 0)) { StopSpeak(); PromptBuilder builder = null; try { builder = new PromptBuilder(CultureInfo.CreateSpecificCulture(_culture)); } catch (Exception ex) { builder = new PromptBuilder(); Console.WriteLine(ex.Message); } builder.AppendTextWithHint(message, sayAs); _speechSynth.SpeakAsync(builder); } }
/// <summary> /// 字符串是当作一个完整的数字来读,而不是拼读。例如:12 读作“十二”,而不是“一二” /// </summary> /// <param name="builder"></param> /// <param name="textToAdd"></param> public static void Add_As_Number_Text(ref PromptBuilder builder, string textToAdd) { builder.AppendTextWithHint(textToAdd, System.Speech.Synthesis.SayAs.NumberCardinal); }
public void TTS(string text) { PromptBuilder pb = new PromptBuilder(); pb.AppendText("This is a date"); pb.AppendBreak(); pb.AppendTextWithHint("31-12-2007", SayAs.DayMonthYear); //PromptBuilder(pb); }
/// <summary> /// This function reads all text from within an interior node of the MathML construct. /// </summary> /// <param name="node">The node to recursively process ("0" would read the entire formula)</param> /// <returns>A PromptBuilder representing a spoken rendering of the specified MathML node</returns> private PromptBuilder ReadNode( System.Xml.XmlNode node ) { // This function reads all text from within an interior node of the MathML construct. It // is designed to recursively iterate on all non-trivial MathML elements. In other words, // it reads all <mo>, <mi>, <mn>, <mtext>, and raw text within the node, but recursively // iterates on all children of this node that are not any of the named tags (like <mroot>, // <mfrac>, <msubsup>, etc.) TimeSpan shortPause = new TimeSpan( 0, 0, 0, 0, 50 ); TimeSpan longPause = new TimeSpan( 0, 0, 0, 0, 250 ); PromptBuilder p = new PromptBuilder(); p.AppendText( " " ); // Return an empty PromptBuilder if the node is empty if( node == null ) return p; // These elements need to be parsed //if (node.Name == "mrow") p.AppendPromptBuilder(ReadNode(node, mo, mi)); if( node.Name == "mfrac" ) { // Fraction p.AppendBreak( shortPause ); p.AppendText( " Start fraction " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 0 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " over " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 1 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " End fraction " ); p.AppendBreak( longPause ); return p; } if( node.Name == "msqrt" ) { // Square Root p.AppendBreak( shortPause ); p.AppendText( " The square root of " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 0 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " End Square root " ); p.AppendBreak( longPause ); return p; } if( node.Name == "mroot" ) { // Generic Root PromptBuilder rootValue = new PromptBuilder(); p.AppendBreak( shortPause ); p.AppendText( " Thee " ); // Read Radical may stylize the radical (square, cube, first, twelfth, etc.) rootValue = ReadRadical( node.ChildNodes.Item( 1 ) ); p.AppendPromptBuilder( rootValue ); p.AppendBreak( shortPause ); p.AppendText( " Root of " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 0 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " End root " ); p.AppendBreak( longPause ); return p; } if( node.Name == "msub" ) { // Subscript p.AppendBreak( shortPause ); p.AppendText( " Subscripted text " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 0 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " Subscript " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 1 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " End subscript " ); p.AppendBreak( longPause ); return p; } if( node.Name == "msup" ) { // Superscript if( MENU_Options_ReadAsPower.Checked ) { // Read as a power bool isBaseSimple = TestForSimpleExpression( node.ChildNodes.Item( 0 ) ); if( isBaseSimple ) { // Read naturally if the base is simple p.AppendBreak( shortPause ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 0 ) ) ); p.AppendPromptBuilder( ReadExponent( node.ChildNodes.Item( 1 ) ) ); } else { // Otherwise, read more formally p.AppendBreak( shortPause ); p.AppendText( " Power Base" ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 0 ) ) ); p.AppendBreak( shortPause ); p.AppendPromptBuilder( ReadExponent( node.ChildNodes.Item( 1 ) ) ); p.AppendText( " End power " ); p.AppendBreak( longPause ); } } else { // Read very formally as a superscript p.AppendBreak( shortPause ); p.AppendText( " Superscripted text " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 0 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " Superscript " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 1 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " End superscript " ); p.AppendBreak( longPause ); } return p; } if( node.Name == "msubsup" ) { // Subscript/superscript p.AppendBreak( shortPause ); p.AppendText( " Sub and super scripted text " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 0 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " Subscript " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 1 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " Superscript " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 2 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " End superscript " ); p.AppendBreak( longPause ); return p; } if( node.Name == "mover" ) { // Over p.AppendBreak( shortPause ); p.AppendText( " Start over text " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 1 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " over " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 0 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " End over text " ); p.AppendBreak( longPause ); return p; } if( node.Name == "munder" ) { // Under p.AppendBreak( shortPause ); p.AppendText( " Start under text " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 1 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " under " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 0 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " End under text " ); p.AppendBreak( longPause ); return p; } if( node.Name == "munderover" ) { // Under/Over p.AppendBreak( shortPause ); p.AppendText( " Start over/under text " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 1 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " over " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 2 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " under " ); p.AppendPromptBuilder( ReadNode( node.ChildNodes.Item( 0 ) ) ); p.AppendBreak( shortPause ); p.AppendText( " End over/under text " ); p.AppendBreak( longPause ); return p; } if( node.Name == "mfenced" ) { // Fenced (a set of numbers/variables) if( ( node.PreviousSibling != null ) && ( node.PreviousSibling.Name == "mi" ) ) { // Read as a Function parameter set p.AppendBreak( shortPause ); p.AppendText( " of " ); int counter = 1; foreach( XmlNode n in node.ChildNodes ) { p.AppendPromptBuilder( ReadNode( n ) ); if ( counter++ < node.ChildNodes.Count ) p.AppendText( " and " ); //counter++; p.AppendBreak( shortPause ); } if ( node.ChildNodes.Count > 1 ) p.AppendText( " end parameters " ); p.AppendBreak( longPause ); return p; } else { // Read as an ordinary set p.AppendBreak( shortPause ); p.AppendText( " Open set " ); foreach( XmlNode n in node.ChildNodes ) { p.AppendPromptBuilder( ReadNode( n ) ); p.AppendBreak( longPause - shortPause ); } p.AppendText( " Close set " ); p.AppendBreak( longPause ); return p; } } for( int i = 0; i < node.ChildNodes.Count; i++ ) { System.Xml.XmlNode readNode = node.ChildNodes.Item( i ); if( readNode.Name == "#text" ) { p.AppendText( " " + readNode.InnerText + " " ); // This is straight text p.AppendBreak( shortPause ); } if( readNode.Name == "mn" ) p.AppendText( readNode.InnerText + " " ); // This is a number if( readNode.Name == "mo" ) // This is an operator { // Must search master list for its pronunciation for( int j = 0; j < ( MasterToken._moCount ); j++ ) { Token t = MasterToken._mo[ j ]; if( readNode.InnerText == t._symbol ) { // Barf. Need this hack because Invisible Plus does not render correctly... so it looks like Invisible Times. if( t._symbol == "" ) { // If t.symbol is Invisible Times, check if it should be Invisible Plus if( ( readNode.PreviousSibling.Name == "mn" ) & ( readNode.NextSibling.Name == "mfrac" ) ) { // Ah. In this case, find how to say Invisible Plus for( int k = 0; k < MasterToken._moCount; k++ ) if( MasterToken._mo[ k ]._symbol == "" ) p.AppendText( MasterToken._mo[ k ]._speech + " " ); } else p.AppendText( t._speech + " " ); } else p.AppendText( t._speech + " " ); } } // Check the mo group } if( readNode.Name == "mi" ) // This is a letter or symbol { bool speakMi = true; // Check for symbols first... if not found in the master list, the token will be pronouced as a letter for( int j = 0; j < ( MasterToken._miCount ); j++ ) { Token t = MasterToken._mi[ j ]; if( readNode.InnerText == t._symbol ) { p.AppendText( t._speech + " " ); speakMi = false; break; } } // Check the mi group if( speakMi ) p.AppendTextWithHint( Convert.ToString( readNode.InnerText ) + " ", SayAs.SpellOut ); } // Basically, if this node is not named one of these things, then it should be // read now. This means <mrow> and <mtext> elements. if( ( readNode.Name != "mi" ) && ( readNode.Name != "mo" ) && ( readNode.Name != "mn" ) && ( readNode.Name != "#text" ) ) p.AppendPromptBuilder( ReadNode( readNode ) ); } // Make sure that a trailing space is appended to the end of an <mrow> element if( node.Name == "mrow" ) p.AppendText( " " ); return p; }
/// <summary> /// This function reads an excerpt of MathML from "LISTBOX_ShowExcerpts". /// </summary> /// <param name="excerpt">The ID of the MathML excerpt to read</param> /// <param name="goDeeper">True to read ID tags recursively, false to read ID tags woodenly</param> /// <returns>A PromptBuilder representing a spoken rendering of the specified math excerpt</returns> private PromptBuilder ReadText( int excerpt, bool goDeeper ) { PromptBuilder p = new PromptBuilder(); string excerptAndPrompt = LISTBOX_ShowExcerpts.Items[ excerpt ].ToString(); string excerptTag = GetXmlWrapper( excerptAndPrompt ); //excerptTag = excerptTag.Substring( 6 ); string tx = RetrieveExcerptFromListbox( excerptAndPrompt ); Char[] c = tx.ToCharArray(); bool speakMiChar = true; // These checks will determine if extra words are needed to delineate that we are in a // special mathML tag bool spokeTag = false; string textExcerpt = ""; for( int j = 1; j < ( MasterToken._elemCount ); j++ ) { Token t = MasterToken._mathMLelement[ j ]; if( excerptTag == t._symbol ) { p.AppendText( t._speech ); spokeTag = true; } if( t._symbol == "mtext" ) textExcerpt = MasterToken._elemEnglish[ j ][ 0 ]; } // Check the mo group if( !spokeTag ) p.AppendText( excerptTag ); p.AppendBreak( new TimeSpan( 0, 0, 0, 0, 250 ) ); // Check for Text tag; should be read literally if( ( excerptTag == "mtext" ) | ( excerptTag == textExcerpt ) ) { p.AppendText( tx ); return p; } // This function will convert the text in the Textbox to speech for( int i = 0; i < ( tx.Length ); i++ ) { // Letters convert to an <m:mi> tag if( Char.IsLetter( c[ i ] ) & ( Convert.ToInt32( c[ i ] ) < 256 ) ) { // Greek letters are considered letters! // First, check if this letter begins a function name! speakMiChar = true; for( int j = 0; j < ( MasterToken._miCount ); j++ ) { Token t = MasterToken._mi[ j ] as Token; string sym = t._symbol; if( sym.Length <= ( tx.Length - i ) ) { if( tx.Substring( i, sym.Length ) == sym ) { p.AppendText( t._speech + " " ); i = i + sym.Length - 1; speakMiChar = false; break; } } } // Check the mi group if( speakMiChar ) p.AppendTextWithHint( Convert.ToString( c[ i ] ) + " ", SayAs.SpellOut ); } // Letter check if( Char.IsDigit( c[ i ] ) || c[ i ] == '.' ) { int startNum = i; int finNum = i; for( finNum = i; finNum < tx.Length; finNum++ ) if( !Char.IsDigit( c[ finNum ] ) && c[ finNum ] != '.' && c[ finNum ] != ',' ) break; string sayNum = ""; for( int k = i; k < finNum; k++ ) sayNum += c[ k ]; sayNum = Convert.ToDouble( sayNum ).ToString(); p.AppendTextWithHint( sayNum + " ", SayAs.Text ); i = finNum - 1; } // check for Numbers if( i < tx.Length ) { // Otherwise, must find the speech text in the Master Token List XML int j = 0; for( j = 0; j < ( MasterToken._moCount ); j++ ) { Token t = MasterToken._mo[ j ] as Token; Char[] sym = t._symbol.ToCharArray(); if( c[ i ] == sym[ 0 ] ) p.AppendText( t._speech + " " ); } // Check the mo group if( speakMiChar ) { for( j = 0; j < ( MasterToken._miCount ); j++ ) { Token t = MasterToken._mi[ j ] as Token; string sym = t._symbol; if( ( i + sym.Length ) < tx.Length ) if( tx.Substring( i, sym.Length ) == sym ) p.AppendText( t._speech + " " ); } // Check the mi group } // ⊰- Finally, we need to test for Excerpt tags! if( c[ i ] == '⊰' ) { int thisID = Convert.ToInt32( tx.Substring( i + 1, 3 ) ); if( goDeeper == true ) { PromptBuilder appendThis = new PromptBuilder(); appendThis = ReadText( thisID, true ); p.AppendPromptBuilder( appendThis ); } else { p.AppendText( "Line " ); p.AppendText( thisID.ToString() + " " ); } i = i + 4; } // Check for excerpt tags // -⊱ p.AppendBreak( new TimeSpan( 0, 0, 0, 0, 125 ) ); } } return p; }
/// <summary> /// Speaks asynchronously /// </summary> /// <param name="message">Message to speak</param> /// <param name="sayAs">Type of pronunciation</param> public void SpeakAsync(string message, SayAs sayAs = SayAs.Text) { if (_enabled && (_voices.Count > 0)) { StopSpeak(); PromptBuilder builder = null; try { builder = new PromptBuilder(CultureInfo.CreateSpecificCulture(_culture)); } catch (Exception e) { builder = new PromptBuilder(); } builder.AppendTextWithHint(message, sayAs); _speechSynth.SpeakAsync(builder); } }
private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { sRecognize.RecognizeAsyncCancel(); //MessageBox.Show("Speech Recognised: " + e.Result.Text.ToString()); SetText(e.Result.Text.ToString()); if (e.Result.Text == "sleep") { sleep = true; } else if (e.Result.Text == "wake") { sleep = false; } if (sleep == false) { if (exitcondition == true) { if (e.Result.Text == "yes") { speaktext("Bye Bye"); sSynth.SpeakAsyncCancelAll(); Application.Exit(); } else if (e.Result.Text == "no" || e.Result.Text == "cancel") { exitcondition = false; speaktext("Exit Aborted."); } else { exitcondition = false; } } if (cv == true) { switch (e.Result.Text) { case "David": name = "Microsoft David Mobile"; cv = false; break; case "Hazel": name = "Microsoft Hazel Mobile"; cv = false; break; case "Zira": name = "Microsoft Zira Mobile"; cv = false; break; } } switch (e.Result.Text) { case "exit": case "close": case "quit": speaktext("Are you sure you want to exit?"); exitcondition = true; break; case "minimize": if (!isMinimized) { Invoke(new Action(() => { this.WindowState = FormWindowState.Minimized; })); isMinimized = true; speaktext("Apologies for coming in your way."); } else { speaktext("I am already minimized!"); } break; case "maximize": if (isMinimized) { Invoke(new Action(() => { this.WindowState = FormWindowState.Normal; })); isMinimized = false; speaktext("I'm back!"); } else { speaktext("I am already maximized!"); } break; case "hello": case "hi": //speaktext("Hello,"+Environment.UserName+", What can I do for you?"); speaktext("Hello, what can I do for you?"); break; case "change voice": cv = true; foreach (InstalledVoice voice in sSynth.GetInstalledVoices()) { VoiceInfo info = voice.VoiceInfo; vn += info.Name + ", "; } speaktext("Select a voice "); speaktext(vn); vn = ""; break; case "how are you": speaktext("I am fine, and you?"); break; case "who are you": speaktext("I am Jarvis your personal assistant"); break; case "open firefox": case "browser": Process.Start(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"); speaktext("Firing your web browser"); break; case "close firefox": case "close browser": killProg("firefox"); break; case "next": SendKeys.SendWait("{RIGHT}"); break; case "previous": case "back": SendKeys.SendWait("{LEFT}"); break; case "play": case "pause": SendKeys.SendWait(" "); break; case "escape": SendKeys.SendWait("{ESC}"); break; case "what is today's date": case "date": pBuilder.ClearContent(); pBuilder.AppendText("Today's date is, "); pBuilder.AppendTextWithHint(DateTime.Now.ToString("M/dd/yyyy"), SayAs.Date); sSynth.SelectVoice(name); //sSynth.Rate = -2; sSynth.Speak(pBuilder); break; case "what time is now": case "time": pBuilder.ClearContent(); pBuilder.AppendText("It is, "); pBuilder.AppendTextWithHint(DateTime.Now.ToString("hh:mm tt"), SayAs.Time12); sSynth.SelectVoice(name); //sSynth.Rate = -2; sSynth.Speak(pBuilder); break; case "how's the weather": case "weather": if (getweather()) { speaktext("The weather in " + Town + " is " + Condition + " at " + Temperature + " degrees celsius. There is a wind speed of " + Windspeed + " kilometers per hour and a humidity of " + Humidity); } else { speaktext("Sorry! Error retrieving weather info."); } break; case "what's tomorrow's forecast": case "forecast": getweather(); speaktext("It looks like tomorrow will be " + TFCond + " with a high of " + TFHigh + " degree centrigrade and a low of " + TFLow + " degree centrigrade"); break; default: if (e.Result.Text.ToString().ToLower().Contains("search")) { string query = e.Result.Text.ToString().Replace("search", ""); query = HttpUtility.UrlEncode(query); pr.StartInfo.FileName = "http://google.com/search?q=" + query; pr.Start(); speaktext("Here is your search result."); } break; } } sRecognize.RecognizeAsync(RecognizeMode.Multiple); }
public void Say(string ID, string msg) { //voice.Speak(text, SpeechVoiceSpeakFlags.SVSFlagsAsync); //voice.WaitUntilDone(10000); if (ID == "") { foreach (string key in voices.Keys) { Say(key, msg); } } else { if (!voices.ContainsKey(ID)) { Form1.updateLog("ERR: Tried to speak to non-existent voice " + ID, ELogLevel.Error, ELogType.SpeechOut); return; } SpeechSynthesizer voice = voices[ID]; voice.Rate = -1; voice.Volume = 100; PromptBuilder pb = new PromptBuilder(); pb.AppendTextWithHint(msg, SayAs.Text); if (outStreams[ID] != null && (outStreams[ID] is FIFOStream)) { while (((FIFOStream)outStreams[ID]).GetWriteLock(this) == null) ; //TODO: Sleep or something } voice.Speak(pb); if (outStreams[ID] != null && (outStreams[ID] is FIFOStream)) { ((FIFOStream)outStreams[ID]).ReturnWriteLock(this); } } }
/// <summary> /// 24小时时间表示法。例如 13:35 /// </summary> /// <param name="builder"></param> /// <param name="textToAdd"></param> public static void Add_As_Time24_Text(ref PromptBuilder builder, string textToAdd) { builder.AppendTextWithHint(textToAdd, System.Speech.Synthesis.SayAs.Time24); }