void Disable() { recognizer.Recognizing -= RecognizingHandler; recognizer.Recognized -= RecognizedHandler; recognizer.Canceled -= CanceledHandler; pushStream.Close(); recognizer.Dispose(); }
void DisableSpeechRecognizer() { _speechRecognizer.Recognizing -= SpeechRecognizingHandler; _speechRecognizer.Recognized -= SpeechRecognizedHandler; _speechRecognizer.Canceled -= SpeechCanceledHandler; _pushStream.Close(); _speechRecognizer.Dispose(); }
public async Task Stop() { _inputStream.Close(); if (_recognizer != null) { _recognizer.SessionStarted -= RecognizerStarted; _recognizer.Recognized -= RecognizerRecognized; await _recognizer.StopContinuousRecognitionAsync(); } }
/// <summary> /// Creates Recognizer with baseline model and selected language: /// Creates a config with subscription key and selected region /// If input source is audio file, creates recognizer with audio file otherwise with default mic /// Waits on RunRecognition. /// </summary> private async Task CreateRecognizer(byte[] channel) { // Todo: suport users to specifiy a different region. var config = SpeechConfig.FromSubscription(this.SubscriptionKey, this.Region); config.SpeechRecognitionLanguage = this.RecognitionLanguage; config.OutputFormat = OutputFormat.Detailed; SpeechRecognizer basicRecognizer; PushAudioInputStream pushStream = AudioInputStream.CreatePushStream(); pushStream.Write(channel); pushStream.Close(); using (var audioInput = AudioConfig.FromStreamInput(pushStream)) { using (basicRecognizer = new SpeechRecognizer(config, audioInput)) { await this.RunRecognizer(basicRecognizer, stopBaseRecognitionTaskCompletionSource).ConfigureAwait(false); } } }
private async Task InjectStreamIntoRecognizerAsync(PushAudioInputStream audioInputStream, BlobClient blobStream) { using (var stream = await blobStream.OpenReadAsync()) { var decoder = new OpusDecoder(16000, 1); var opus = new OpusOggReadStream(decoder, stream); while (opus.HasNextPacket) { short[] packet = opus.DecodeNextPacket(); if (packet != null) { for (int i = 0; i < packet.Length; i++) { var bytes = BitConverter.GetBytes(packet[i]); audioInputStream.Write(bytes, bytes.Length); } } } } audioInputStream.Close(); }