public override void ViewDidLoad() { base.ViewDidLoad(); ss = new AVSpeechSynthesizer(); ss.DidFinishSpeechUtterance += (object sender, AVSpeechSynthesizerUteranceEventArgs e) => { }; ss.DidStartSpeechUtterance += (object sender, AVSpeechSynthesizerUteranceEventArgs e) => { }; ss.WillSpeakRangeOfSpeechString += (object sender, AVSpeechSynthesizerWillSpeakEventArgs e) => { }; nlp = new NaturalLanguageProcessor.NaturalLanguageProcessor(); nlp.SetConfiguration(File.ReadAllText("RPRSpeechIntents.json"), File.ReadAllText("RPRScreenContexts.json")); recordButton.Enabled = false; this.pickerView.Model = new ScreensModel(this, nlp.ContextConfigurations.Select(cc => cc.Name).ToList()); speechIdleTimer = new System.Timers.Timer(3 * 1000); speechIdleTimer.Elapsed += (sender, e) => { this.stopSpeechRecognition(); speechIdleTimer.Stop(); }; }
public static void Main(string [] args) { var nlp = new NaturalLanguageProcessor.NaturalLanguageProcessor(); var intentConfigurations = JsonConvert.DeserializeObject <List <IntentConfiguration> > (File.ReadAllText("RPRSpeechIntents.json")).ToList(); var contextConfigurations = JsonConvert.DeserializeObject <List <ContextConfiguration> > (File.ReadAllText("RPRScreenContexts.json")).ToList(); nlp.SetConfiguration(intentConfigurations, contextConfigurations); while (true) { Console.WriteLine("Which screen are you in?"); string screen = Console.ReadLine(); var suggestions = nlp.GetSuggestions(screen); if (suggestions != null) { Console.WriteLine("Some things you can ask me:"); suggestions.ForEach(s => { Console.WriteLine(s); }); } else { Console.WriteLine("Sorry, I do not understand the context."); break; } Console.WriteLine("Okay, go ahead, I am listening"); string userSearch = Console.ReadLine(); var intentResult = nlp.GetMatchingIntent(userSearch); if (intentResult != null) { Console.WriteLine("Awesome, I will get it done."); Console.WriteLine("Action: " + intentResult.Action); if (intentResult.Parameters != null) { foreach (var paramter in intentResult.Parameters) { Console.WriteLine("Parameter Name: " + paramter.Key); Console.WriteLine("Parameter Values: " + string.Join(", ", paramter.Value)); } } else { Console.WriteLine("No specific parameters mentioned."); } } else { Console.Write("Sorry, I do not understand that."); } Console.ReadLine(); } }
protected override void OnCreate(Bundle bundle) { SetContentView(Resource.Layout.Main); nlp.SetConfiguration(ReadAssetFile("RPRSpeechIntents.json"), ReadAssetFile("RPRScreenContexts.json")); #region Initialization TextToSpeech textToSpeech; SpeechRecognizer mSpeechRecognizer; Intent mSpeechRecognizerIntent; var lang = Java.Util.Locale.Default; base.OnCreate(bundle); var screenDropDownList = FindViewById <Spinner>(Resource.Id.ScreenList); var showListButton = FindViewById <Button>(Resource.Id.btnShowScreen); var micButton = FindViewById <ImageButton>(Resource.Id.btnMic); var btnSayIt = FindViewById <Button>(Resource.Id.btnSpeak); var textView = FindViewById <TextView>(Resource.Id.SpeechTextView); var voiceImage = FindViewById <Android.Webkit.WebView>(Resource.Id.voiceWebView); dropdownLists = nlp.ContextConfigurations.Select(cc => cc.Name).ToList(); dropdownLists.Insert(0, "<Select Screen..>"); voiceImage.Visibility = ViewStates.Invisible; textView.Text = "Hello There! Kindly Select a Screen!"; btnSayIt.Visibility = ViewStates.Invisible; micButton.Visibility = ViewStates.Invisible; textToSpeech = new TextToSpeech(this, this, "com.google.android.tts"); textToSpeech.SetLanguage(lang); screenDropDownList.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(dropdown_ItemSelected); screenDropDownList.Visibility = ViewStates.Invisible; var spinnerArrayAdapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SelectDialogSingleChoice, dropdownLists); spinnerArrayAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerItem); screenDropDownList.Adapter = spinnerArrayAdapter; screenDropDownList.SetSelection(-1); #endregion #region ButtonClickEvents showListButton.Click += delegate { if (screenDropDownList.Visibility == ViewStates.Visible) { showListButton.Text = "Select Screen"; screenDropDownList.Visibility = ViewStates.Invisible; } else { showListButton.Text = "Hide Screen"; textView.Text = "Hello There! Kindly Select a Screen!"; screenDropDownList.Visibility = ViewStates.Visible; } }; micButton.Click += delegate { mSpeechRecognizer = SpeechRecognizer.CreateSpeechRecognizer(this); mSpeechRecognizerIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech); mSpeechRecognizerIntent.PutExtra(RecognizerIntent.ExtraCallingPackage, PackageName); mSpeechRecognizerIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1000); mSpeechRecognizerIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1000); mSpeechRecognizerIntent.PutExtra(RecognizerIntent.ExtraMaxResults, 1); mSpeechRecognizerIntent.PutExtra(RecognizerIntent.ExtraLanguageModel, this.Resources.Configuration.Locale.Language); mSpeechRecognizer.SetRecognitionListener(this); mSpeechRecognizer.StartListening(mSpeechRecognizerIntent); }; btnSayIt.Click += delegate { if (!string.IsNullOrEmpty(speakText)) { textToSpeech.Speak(speakText, QueueMode.Flush, null, null); } }; #endregion }