private async void OnRecognitionButtonClicked(object sender, EventArgs e)
        {
            bool locationAccessGranted = await DependencyService.Get <ILocationService>().GetPermissionsAsync();

            if (!locationAccessGranted)
            {
                UpdateUI("Please give location access.");
            }

            if (_recognizer == null)
            {
                _recognizer = new KeywordRecognizer(AudioConfig.FromDefaultMicrophoneInput());
            }
            if (_model == null)
            {
                var kwsModelDir = DependencyService.Get <IFileSystemService>().GetWakeWordModelPath(kwsModelFile);
                _model = KeywordRecognitionModel.FromFile(kwsModelDir);
            }

            UpdateUI("Say wakeword to start recording speech.");
            _result = await _recognizer.RecognizeOnceAsync(_model).ConfigureAwait(false);

            var locationResult = await DependencyService.Get <ILocationService>().GetCurrentGPSCoordinatesAsync();

            string message = $"Detected keyword at TIME: {DateTime.Now} and LOCATION: {locationResult}";

            UpdateUI(message);

//            UpdateUI("Got a keyword, now you can keep talking...");
//            await DoSpeechRecognition().ConfigureAwait(false);
        }
Exemplo n.º 2
0
        //////////////////////////////////////////////////////////////   LISTENING COMMANDS   ////////////////////////////////////////////////////////////////////////////////////
        public static async Task RecognizeSpeechAsync()
        {
            Console.Clear();
            Console.WriteLine("Please Say 'Hey Rosita' to begin");
            var keywordModel = KeywordRecognitionModel.FromFile("C:\\Users\\Johnny\\Documents\\GitHub\\Rosita\\Rosita\\827f85af-e8cd-44ad-8d48-1963414c3bde.table");

            using var audioConfig10     = AudioConfig.FromDefaultMicrophoneInput();
            using var keywordRecognizer = new KeywordRecognizer(audioConfig10);
            KeywordRecognitionResult keyresult = await keywordRecognizer.RecognizeOnceAsync(keywordModel);

            var config =
                SpeechConfig.FromSubscription(
                    "aabb8086039843e7b4339dd4928f2de1",
                    "eastus");

            using var audioConfig = AudioConfig.FromDefaultMicrophoneInput();
            using var recognizer  = new SpeechRecognizer(config, audioConfig);

            Console.WriteLine("Say something...");
            var result = await recognizer.RecognizeOnceAsync();

            string command = result.Text;

            switch (result.Reason)
            {
            case ResultReason.RecognizedSpeech:
                Console.WriteLine($"RECOGNIZED: Text={result.Text}");
                break;

            case ResultReason.NoMatch:
                Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                break;

            case ResultReason.Canceled:
                var cancellation = CancellationDetails.FromResult(result);
                Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");

                if (cancellation.Reason == CancellationReason.Error)
                {
                    Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
                    Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
                    Console.WriteLine($"CANCELED: Did you update the subscription info?");
                }
                break;
            }
            //////////////////////////////////////////////////////////////   LISTENING COMMANDS END   /////////////////////////////////////////////////////////////////////////
            ///
            ///
            ///
            /////////////////////////////////////////////////////////////////////   LINK TO KEY PHRASES   ////////////////////////////////////////////////////////////////////////////

            await Speech.TalkingAsync(command.ToLower());

            /////////////////////////////////////////////////////////////////////   LINK TO KEY PHRASES END  ////////////////////////////////////////////////////////////////////////////
        }
Exemplo n.º 3
0
        private async void RecognizeKeywordButton_Click(object sender, RoutedEventArgs e)
        {
            RecognizeKeywordButton.IsEnabled = false;

            if (recognizer == null)
            {
                recognizer = new KeywordRecognizer(AudioConfig.FromDefaultMicrophoneInput());
            }
            if (model == null)
            {
                await InitializeKeywordModel();
            }

            NotifyUser("Say \"Computer\"", NotifyType.StatusMessage);
            result = await recognizer.RecognizeOnceAsync(model);

            NotifyUser("Got a keyword, now you can keep talking...", NotifyType.StatusMessage);
            SaveToFileButton.IsEnabled = true;
        }