private void startSpeechRecognition() { isFeeding = true; stream = client.CreateStream(); var feedCount = 0; var decodeRate = 100; // decode every 100 feeds Task.Run(async() => { while (isFeeding || !bufferQueue.IsEmpty) { if (!bufferQueue.IsEmpty && bufferQueue.TryDequeue(out short[] buffer)) { client.FeedAudioContent(stream, buffer, Convert.ToUInt32(buffer.Length)); if (++feedCount % decodeRate == 0) { var transcription = client.IntermediateDecode(stream); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { result.Text = transcription; }); } } } }); }
/// <summary> /// Starts processing data from the queue. /// </summary> private void OnNewData() { try { while (!StreamingIsBusy && !_bufferQueue.IsEmpty) { if (_bufferQueue.TryDequeue(out short[] buffer)) { StreamingIsBusy = true; mSttClient.FeedAudioContent(mSttStream, buffer, Convert.ToUInt32(buffer.Length)); StreamingIsBusy = false; } } } catch (Exception e) { Console.WriteLine(e.Message); } }