public GoogleSpeechRecognizer(ISpeechOutput output, ActivationWord[] activators, float activationConfidence, float commandConfidence, string captureDeviceName) { GoogleSpeechApiUtils.Authorize(); _output = output; Activators = activators; ActivationConfidence = activationConfidence; CommandConfidence = commandConfidence; CaptureDeviceIndex = Utils.GetCaptureDeviceIndex(captureDeviceName); _activator = new MicrosoftSpeechRecognizer(activationConfidence, captureDeviceName); _activator.Keywords = activators.Select(x => Utils.PrepareActivatorString(x.Word)).ToArray(); foreach (var activator in activators) { if (activator is ActivatorWord_StartGoogleRecognition _googleRecognition) { _googleRecognition.SetAction(async(args) => await ActivateInternalAsync(args.ActivatorContinue)); } } _activator.Activated += (o, e) => { new Thread(() => { var args = e as ActivatorEventArgs; bool found = false; foreach (var activator in activators) { if (Utils.CompareActivatorPhrases(activator.Word, args.Word)) { activator.Activate((ActivatorEventArgs)e); found = true; break; } } if (!found) { args.ActivatorContinue(); } }) { IsBackground = true, Priority = ThreadPriority.Highest } .Start(); }; }
public ActivatorEventArgs(ISpeechActivator recognizer) => _recognizer = recognizer;