示例#1
0
        //NOTE: According to the GitHub Issues, receiving voice requires transmitting audio first.
        public async Task ListenAsync(Action onRecognizedSpeech)
        {
            if (inputClient == null)
            {
                throw new NullReferenceException("Input was null");
            }

            cancellationTokenSource = new CancellationTokenSource();

            audio.SetOutput(inputClient);
            await audio.PlaySilenceAsync(1); // Play audio so we can receive.

            var streams = inputClient.GetStreams().Values;

            Parallel.ForEach(streams, stream =>
            {
                using (stream)
                {
                    var recognizer = new SAPIVoiceRecognizer(cancellationTokenSource.Token);
                    recognizer.RecognizeAsync("run", (InputStream)stream, onRecognizedSpeech).Wait();
                }
            });
        }