Created
August 25, 2018 15:50
-
-
Save dev-aritra/cba778431fc23d6c87e3428faff1d1c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Android.App; | |
using Android.Content; | |
using Android.OS; | |
using Android.Runtime; | |
using Android.Speech; | |
using Android.Views; | |
using Android.Widget; | |
using Plugin.CurrentActivity; | |
using XFSpeechDemo.Droid; | |
[assembly: Xamarin.Forms.Dependency(typeof(SpeechToTextImplementation))] | |
namespace XFSpeechDemo.Droid | |
{ | |
public class SpeechToTextImplementation : ISpeechToText | |
{ | |
private readonly int VOICE = 10; | |
private Activity _activity; | |
public SpeechToTextImplementation() | |
{ | |
_activity = CrossCurrentActivity.Current.Activity; | |
} | |
public void StartSpeechToText() | |
{ | |
StartRecordingAndRecognizing(); | |
} | |
private void StartRecordingAndRecognizing() | |
{ | |
string rec = global::Android.Content.PM.PackageManager.FeatureMicrophone; | |
if (rec == "android.hardware.microphone") | |
{ | |
var voiceIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech); | |
voiceIntent.PutExtra(RecognizerIntent.ExtraLanguageModel, RecognizerIntent.LanguageModelFreeForm); | |
voiceIntent.PutExtra(RecognizerIntent.ExtraPrompt, "Speak now"); | |
voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1500); | |
voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1500); | |
voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 15000); | |
voiceIntent.PutExtra(RecognizerIntent.ExtraMaxResults, 1); | |
voiceIntent.PutExtra(RecognizerIntent.ExtraLanguage, Java.Util.Locale.Default); | |
_activity.StartActivityForResult(voiceIntent, VOICE); | |
} | |
} | |
public void StopSpeechToText() | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment