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
public interface ISpeechToText | |
{ | |
void StartSpeechToText(); | |
void StopSpeechToText(); | |
} |
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 AVFoundation; | |
using Foundation; | |
using Speech; | |
using System; | |
using Xamarin.Forms; | |
using XFSpeechDemo.iOS; | |
[assembly: Xamarin.Forms.Dependency(typeof(SpeechToTextImplementation))] | |
namespace XFSpeechDemo.iOS | |
{ |
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
private void AskForSpeechPermission() | |
{ | |
SFSpeechRecognizer.RequestAuthorization((SFSpeechRecognizerAuthorizationStatus status) => | |
{ | |
switch (status) | |
{ | |
case SFSpeechRecognizerAuthorizationStatus.Authorized: | |
MessagingCenter.Send<ISpeechToText>(this, "Authorized"); | |
break; | |
case SFSpeechRecognizerAuthorizationStatus.Denied: |
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
private AVAudioEngine _audioEngine = new AVAudioEngine(); | |
private SFSpeechRecognizer _speechRecognizer = new SFSpeechRecognizer(); | |
private SFSpeechAudioBufferRecognitionRequest _recognitionRequest; | |
private SFSpeechRecognitionTask _recognitionTask; | |
private string _recognizedString; | |
private NSTimer _timer; | |
private bool isNotContinious; |
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
public void StartSpeechToText() | |
{ | |
if (_audioEngine.Running) | |
{ | |
StopRecordingAndRecognition(); | |
} | |
StartRecordingAndRecognizing(); | |
} |
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
private void StartRecordingAndRecognizing() | |
{ | |
if(isNotContinious) | |
{ | |
_timer = NSTimer.CreateRepeatingScheduledTimer(5, delegate | |
{ | |
DidFinishTalk(); | |
}); | |
} | |
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
MessagingCenter.Subscribe<ISpeechToText, string>(this, "STT", (sender, args) => { | |
Console.WriteLine(args); | |
}); | |
MessagingCenter.Subscribe<ISpeechToText>(this, "Final", (sender) => { | |
Console.WriteLine("Recognition finished"); | |
}); |
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
string rec = global::Android.Content.PM.PackageManager.FeatureMicrophone; | |
if (rec == "android.hardware.microphone") | |
{ | |
} |
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.Views; |
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
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"); |
OlderNewer