Skip to content

Instantly share code, notes, and snippets.

@itanium21
Created September 1, 2016 17:37
Show Gist options
  • Save itanium21/1d05beb545a46e6031514e9c20c86297 to your computer and use it in GitHub Desktop.
Save itanium21/1d05beb545a46e6031514e9c20c86297 to your computer and use it in GitHub Desktop.
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Speech;
using Android.Content;
using System;
using System.Collections.Generic;
namespace Quizer.Droid
{
[Activity (Label = "Quizer.Droid", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity, IRecognitionListener
{
private SpeechRecognizer mSpeechRecognizer;
private Intent mSpeechRecognizerIntent;
int count;
Button recButton;
private TextView textBox;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
recButton = FindViewById<Button>(Resource.Id.recButton);
textBox = FindViewById<TextView>(Resource.Id.textView1);
mSpeechRecognizer = SpeechRecognizer.CreateSpeechRecognizer(this);
mSpeechRecognizerIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech);
mSpeechRecognizerIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1500);
mSpeechRecognizerIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1500);
mSpeechRecognizerIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 5000);
mSpeechRecognizerIntent.PutExtra(RecognizerIntent.ExtraMaxResults, 1);
mSpeechRecognizerIntent.PutExtra(RecognizerIntent.ExtraLanguageModel, Java.Util.Locale.Default);
//mSpeechRecognizer.SetRecognitionListener(this); // with or without this line
recButton.Click += recButton_Click;
}
void recButton_Click(object sender, EventArgs e)
{
mSpeechRecognizer.StartListening(mSpeechRecognizerIntent);
}
public void OnBeginningOfSpeech()
{
textBox.Text = "1";
throw new NotImplementedException();
}
public void OnBufferReceived(byte[] buffer)
{
textBox.Text = "2";
throw new NotImplementedException();
}
public void OnEndOfSpeech()
{
textBox.Text = "3";
throw new NotImplementedException();
}
public void OnError(SpeechRecognizerError error)
{
textBox.Text = "4";
throw new NotImplementedException();
}
public void OnEvent(int eventType, Bundle @params)
{
textBox.Text = "5";
throw new NotImplementedException();
}
public void OnPartialResults(Bundle partialResults)
{
textBox.Text = "6";
throw new NotImplementedException();
}
public void OnReadyForSpeech(Bundle @params)
{
textBox.Text = "7";
throw new NotImplementedException();
}
public void OnRmsChanged(float rmsdB)
{
textBox.Text = "8";
throw new NotImplementedException();
}
public void OnResults(Bundle results)
{
textBox.Text = "9";
IList<string> matches = results.GetStringArrayList(SpeechRecognizer.ResultsRecognition);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment