Created
June 20, 2016 12:23
-
-
Save dmitry-osin/92772fc299d4b5e7c2870acfa757de76 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
public partial class PhraseSpotterPageViewModel : ViewModels.ViewModelBase.ViewModelBase | |
{ | |
/// <summary> | |
/// Method initialize async SpeechKit for PhraseSpotterCase | |
/// </summary> | |
private void InitSk() | |
{ | |
SpeechKitInitializer.Configure(SKStartupSettings.APIKey); | |
SpeechKitInitializer.InitializeAsync(); | |
IsStartEnabled = true; | |
} | |
/// <summary> | |
/// Init SpeechKit commands | |
/// </summary> | |
private void InitSkCommands() | |
{ | |
StartCommand = new RelayCommand(() => | |
{ | |
_phraseSpotter.Start(); | |
}); | |
StopCommand = new RelayCommand(() => | |
{ | |
_phraseSpotter.StopSync(); | |
if (_phraseSpotter != null) | |
{ | |
_phraseSpotter.ErrorHandler += PhraseSpotterOnErrorHandler; | |
_phraseSpotter.SpottedHandler += PhraseSpotterOnSpottedHandler; | |
_phraseSpotter.StartedHandler += PhraseSpotterOnStartedHandler; | |
_phraseSpotter.StoppedHandler += PhraseSpotterOnStoppedHandler; | |
} | |
}); | |
StopCommandAsync = new RelayCommand(async () => | |
{ | |
await Task.Run(() => | |
{ | |
_phraseSpotter.Stop(); | |
}); | |
_phraseSpotter.ErrorHandler += PhraseSpotterOnErrorHandler; | |
_phraseSpotter.SpottedHandler += PhraseSpotterOnSpottedHandler; | |
_phraseSpotter.StartedHandler += PhraseSpotterOnStartedHandler; | |
_phraseSpotter.StoppedHandler += PhraseSpotterOnStoppedHandler; | |
}); | |
LoadCommand = new RelayCommand(() => | |
{ | |
_phraseSpotter.SetModel(_phraseSpotterModel); | |
_phraseSpotter.ErrorHandler += PhraseSpotterOnErrorHandler; | |
_phraseSpotter.SpottedHandler += PhraseSpotterOnSpottedHandler; | |
_phraseSpotter.StartedHandler += PhraseSpotterOnStartedHandler; | |
_phraseSpotter.StoppedHandler += PhraseSpotterOnStoppedHandler; | |
SpotterModelError = _phraseSpotterModel.Load(); | |
InvokeOnUiThread(() => | |
{ | |
Status = "Model loaded"; | |
}); | |
}); | |
UnloadCommand = new RelayCommand(() => | |
{ | |
SpotterModelError = _phraseSpotterModel.Unload(); | |
InvokeOnUiThread(() => | |
{ | |
Status = "Model unloaded"; | |
}); | |
}); | |
DestroyCommand = new RelayCommand(() => | |
{ | |
_phraseSpotterModel = null; | |
InvokeOnUiThread(() => | |
{ | |
Status = "Model destroyed"; | |
}); | |
}); | |
CreateCommand = new RelayCommand(() => | |
{ | |
_phraseSpotter = new PhraseSpotter(); | |
_phraseSpotterModel = new PhraseSpotterModel(SelectedModelPath); | |
InvokeOnUiThread(() => | |
{ | |
Status = "Model created"; | |
}); | |
}); | |
} | |
#region SpeechKit Event Handlers | |
private void PhraseSpotterOnStoppedHandler() | |
{ | |
InvokeOnUiThread(() => | |
{ | |
Status = "Phrase spotter Stopped"; | |
}); | |
} | |
private void PhraseSpotterOnStartedHandler() | |
{ | |
InvokeOnUiThread(() => | |
{ | |
Status = "Phrase spotter started"; | |
}); | |
} | |
private void PhraseSpotterOnSpottedHandler(string phase, int phaseId) | |
{ | |
InvokeOnUiThread(() => | |
{ | |
LastPhrase = phase; | |
var data2 = phaseId; | |
}); | |
} | |
private void PhraseSpotterOnErrorHandler(Error error) | |
{ | |
InvokeOnUiThread(() => | |
{ | |
LastError = error.Text; | |
}); | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment