Пример #1
0
        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();
            };
        }
Пример #2
0
 private async Task ActivateInternalAsync(Action callback) => await GoogleSpeechApiUtils.StreamingMicRecognizeAsync(5700, _output, callback, CommandConfidence, CaptureDeviceIndex);