Skip to content

Instantly share code, notes, and snippets.

@dev-aritra
Last active August 25, 2018 15:09
Show Gist options
  • Save dev-aritra/df23caa4798cca4448914b632146df1d to your computer and use it in GitHub Desktop.
Save dev-aritra/df23caa4798cca4448914b632146df1d to your computer and use it in GitHub Desktop.
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Speech;
using Xamarin.Forms;
namespace XFSpeechDemo.Droid
{
[Activity(Label = "XFSpeechDemo", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity , IMessageSender
{
private readonly int VOICE = 10;
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
if (requestCode == VOICE)
{
if (resultCode == Result.Ok)
{
var matches = data.GetStringArrayListExtra(RecognizerIntent.ExtraResults);
if (matches.Count != 0)
{
string textInput = matches[0];
MessagingCenter.Send<IMessageSender, string>(this, "STT", textInput);
}
else
{
MessagingCenter.Send<IMessageSender, string>(this, "STT", "No input");
}
}
}
base.OnActivityResult(requestCode, resultCode, data);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment