public void HandleQuery(string input) { string QueryString = input.Substring(14); //Now eliminate that annoying floating '>' once again =p QueryString = QueryString.Substring(0, QueryString.Length - 1); string[] anchors = QueryString.Split(','); string AnchorYes = anchors[0]; string AnchorNo = anchors[1]; String command = "QueryGeneric"; //Now Get the Anchor Objects to reference line numbers Anchor Anchor_Y = FetchAnchor(AnchorYes, command); Anchor Anchor_N = FetchAnchor(AnchorNo, command); //Create The Dialoge for the Generic Query Dialouge GenericQuery = new Dialouge(); GenericQuery.ShowDialog(); if (GenericQuery.ReturnValue == "Yes") { int line_index = Anchor_Y.line_number; index = line_index; } if (GenericQuery.ReturnValue == "No") { int line_index = Anchor_N.line_number; index = line_index; } }
//parse the entire thing out and say the stuff. public void parse(string filename) { //Load the file lines = System.IO.File.ReadAllLines(filename); //Parse the anchors Parse_Anchors(); while (index < lines.Length) { string input = lines[index]; index++; //Parse the context if (input.StartsWith("SetRate:")) { string rate = input.Substring(8); if (Ratevalues.ContainsKey(rate)) { PromptRate pmt_rate = Ratevalues[rate]; style_.Rate = pmt_rate; } } if (input.StartsWith("SetEmp:")) { string Empsetting = input.Substring(7); if (Emphasisvalues.ContainsKey(Empsetting)) { PromptEmphasis emp_val = Emphasisvalues[Empsetting]; style_.Emphasis = emp_val; } } if (input.StartsWith("<Deepener>")) { //Make note of the deepender here. if (!random_lines.ContainsKey(index)) { random_lines.Add(index, "<Deepener>"); } //now we will run a Deepener script here. int Deepener_Count = Deepener_names.Count(); Random r = new Random(); int next_Deepener = r.Next(Deepener_Count); string Deepener_name = Deepener_names[next_Deepener]; //Some recursive magic now SpeechScriptInterpreter Deepener_interpreter = new SpeechScriptInterpreter(); Deepener_interpreter.init(); //Initialize the new interpreter instance Deepener_interpreter.parse(Deepener_name); } if (input.StartsWith("<Goto:")) { string command = "Goto"; //Get the anchor object. Anchor A = FetchAnchor(input, command); //The '!' character is reserved and anchors cannot use it //It is used to denote a failed fetch. To prevent NullErrors. if (A.name != "!") { int line_index = A.line_number; //Assign indirectly the index of this trance to the Anchor index. index = line_index; } } //Change inputs by setting functions for them for more efficient parsing and //Templating of code blocks. if (input.StartsWith("<QueryMulti:")) { QueryMulti(input); } if (input.StartsWith("<QueryDeepEnough>")) { Dialouge get_state = new Dialouge(); say_default("Are you deep enough yet?"); get_state.ShowDialog(); //Find out yes or no string result = get_state.ReturnValue; if (result == "Yes") { continue; } if (result == "No") { for (int i = index; i > 0; i--) { //search backwards for the previous Deepener //Did we find a '<Deepener> tag? if (random_lines.ContainsKey(i)) { if (random_lines[i] == "<Deepener>") { //does it match? //if it does, we go backwards in the script //All the way to this point index = i - 1; break; //We want to quit the search } } } } } //Generic Query if (input.StartsWith("<QueryGeneric:")) { HandleQuery(input); } //Say the stuff, treating our rate and emphasis as part of a state machine //Which we re-apply each time something is to be spoken. if (input.StartsWith("Say:")) { string voice_string = input.Substring(4); builder.ClearContent(); builder.StartSentence(); builder.StartStyle(style_); builder.AppendText(voice_string); builder.EndStyle(); builder.EndSentence(); //lastly let the ball roll and see if we can hear some chatter. reader.Speak(builder); } } }