public virtual void Speak(string message, bool async) { tts.SayTextRequest streq = new tts.SayTextRequest(); streq.SpeechText = message; if (async) { ttsPort.SayText(streq); } else { AutoResetEvent aevent = new AutoResetEvent(false); Arbiter.Activate(DssEnvironment.TaskQueue, Arbiter.Choice(ttsPort.SayText(streq), delegate(DefaultUpdateResponseType state) { aevent.Set(); }, delegate(Fault f) { aevent.Set(); } )); aevent.WaitOne(1000, false); } }
void BumperNotificationHandler(contactsensor.Update updateNotification) { contactsensor.ContactSensor s = updateNotification.Body; if (!s.Pressed) { return; } if (!string.IsNullOrEmpty(s.Name) && s.Name.ToLowerInvariant().Contains("left")) { //say something speech.SayTextRequest saythis = new speech.SayTextRequest(); saythis.SpeechText = "Turning right"; _speechPort.SayText(saythis); //update state _state.CurrentAction = "Turning right"; //move SpawnIterator <int>(-800, BackUpTurnAndMove); } else if (!string.IsNullOrEmpty(s.Name) && s.Name.ToLowerInvariant().Contains("right")) { //say something speech.SayTextRequest saythis = new speech.SayTextRequest(); saythis.SpeechText = "Turning left"; _speechPort.SayText(saythis); //update state _state.CurrentAction = "Turning left"; //move SpawnIterator <int>(800, BackUpTurnAndMove); } else if (!string.IsNullOrEmpty(s.Name) && s.Name.ToLowerInvariant().Contains("stall")) { //say something speech.SayTextRequest saythis = new speech.SayTextRequest(); saythis.SpeechText = "Ouch, let go."; _speechPort.SayText(saythis); //update state _state.CurrentAction = "Turning around"; //move SpawnIterator <int>(800, BackUpTurnAndMove); } }
/// <summary> /// Sends a say text request to the TTS service /// </summary> /// <param name="text">text to be spoken</param> /// <remarks> /// This method executes in the context of the WPF dispatcher. /// Any long running computations or blocking calls would make the /// user interface unresponsive. We simply hand over to DSS/CCR. /// </remarks> internal void SayTextFromUi(string text) { Activate( Arbiter.Choice( _ttsPort.SayText(new texttospeech.SayTextRequest { SpeechText = text }), success => { // nothing to do }, fault => { // the fault handler is outside the WPF dispatcher // to perfom any UI related operation we need to go through the WPF adapter // show an error message _wpfServicePort.Invoke(() => _userInterface.ShowFault(fault)); } ) ); }