private void button1_Click(object sender, EventArgs e) { SpeechScriptInterpreter interpreter = new SpeechScriptInterpreter(); //Call Initialize on the interpreter interpreter.init(); //Call parse so we can hear it talk! Hopefully it can parse the test file. :D. interpreter.parse("Questionaire.txt"); //Old stuff keeping as example below /* * SpeechSynthesizer reader = new SpeechSynthesizer(); * reader.SelectVoice("IVONA 2 Salli"); * PromptBuilder b = new PromptBuilder(); * * * PromptStyle s = new PromptStyle(PromptRate.ExtraFast); * s.Rate = PromptRate.Medium; * s.Volume = PromptVolume.Loud; * s.Emphasis = PromptEmphasis.Strong; * PromptRate. * * * * b.StartSentence(); * b.StartStyle(s); * b.AppendText("Hello Iridescent"); * b.EndStyle(); * b.AppendBreak(new TimeSpan(0, 0, 2)); * s.Emphasis = PromptEmphasis.Reduced; * s.Rate = PromptRate.Fast; * b.StartStyle(s); * b.AppendText("This is less emphasized"); * b.EndStyle(); * b.EndSentence(); * * * * b.AppendBreak(new TimeSpan(0, 0, (int) 1.5)); * b.StartSentence(); * b.AppendText("How", PromptEmphasis.Moderate); * b.AppendText("Are", PromptVolume.Loud); * b.AppendText("You?", PromptEmphasis.Strong); * * b.AppendText("WEEEEEEEEEEEEEEEEEEE"); * b.EndSentence(); * * * reader.Speak(b); * * * // b.StartStyle(c ); * // b.EndStyle(); * b.StartSentence(); * b.AppendText("Hey"); * b.EndSentence(); * b.AppendBreak(new TimeSpan(0, 0, (int)3)); * * * reader.Speak(b); * reader.SpeakCompleted += compl; * reader.Speak(b); * * * * * * * * List<string> vnames = new List<string>(); * foreach (InstalledVoice voice in reader.GetInstalledVoices()) * { * VoiceInfo info = voice.VoiceInfo; * //Console.WriteLine(" Voice Name: " + info.Name); * vnames.Add(info.Name); * } * Console.WriteLine("hello"); * * reader.Speak(b); * * * * for (int i=-10; i<10; i++) * { * reader.Rate = i; * reader.Speak("You will obey"); * reader.Rate = 5; * * } * * */ }
//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); } } }