From 92fff3b61228b4d025d740ccbb37dc64c7006da9 Mon Sep 17 00:00:00 2001 From: Carlos Fonseca M Date: Sat, 18 Jan 2020 12:41:35 +0100 Subject: [PATCH] Update WPF example for multistream API --- net_framework/DeepSpeechWPF/App.xaml.cs | 12 ++++++------ .../DeepSpeechWPF/ViewModels/MainWindowViewModel.cs | 13 ++++++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/net_framework/DeepSpeechWPF/App.xaml.cs b/net_framework/DeepSpeechWPF/App.xaml.cs index 67dad8e..95c550a 100644 --- a/net_framework/DeepSpeechWPF/App.xaml.cs +++ b/net_framework/DeepSpeechWPF/App.xaml.cs @@ -18,20 +18,20 @@ namespace DeepSpeechWPF const int BEAM_WIDTH = 500; - //Register instance of DeepSpeech - DeepSpeechClient.DeepSpeech deepSpeechClient = new DeepSpeechClient.DeepSpeech(); try { - deepSpeechClient.CreateModel("output_graph.pbmm", BEAM_WIDTH); + //Register instance of DeepSpeech + DeepSpeechClient.DeepSpeech deepSpeechClient = + new DeepSpeechClient.DeepSpeech("output_graph.pbmm", BEAM_WIDTH); + + SimpleIoc.Default.Register(() => deepSpeechClient); + SimpleIoc.Default.Register(); } catch (System.Exception ex) { MessageBox.Show(ex.Message); Current.Shutdown(); } - - SimpleIoc.Default.Register(() => deepSpeechClient); - SimpleIoc.Default.Register(); } protected override void OnExit(ExitEventArgs e) diff --git a/net_framework/DeepSpeechWPF/ViewModels/MainWindowViewModel.cs b/net_framework/DeepSpeechWPF/ViewModels/MainWindowViewModel.cs index 81b33ce..207e209 100644 --- a/net_framework/DeepSpeechWPF/ViewModels/MainWindowViewModel.cs +++ b/net_framework/DeepSpeechWPF/ViewModels/MainWindowViewModel.cs @@ -4,6 +4,7 @@ using CSCore.CoreAudioAPI; using CSCore.SoundIn; using CSCore.Streams; using DeepSpeechClient.Interfaces; +using DeepSpeechClient.Models; using GalaSoft.MvvmLight.CommandWpf; using Microsoft.Win32; using System; @@ -58,6 +59,12 @@ namespace DeepSpeech.WPF.ViewModels #endregion #region Streaming + + /// + /// Stream used to feed data into the acoustic model. + /// + private DeepSpeechStream _sttStream; + /// /// Records the audio of the selected device. /// @@ -308,7 +315,7 @@ namespace DeepSpeech.WPF.ViewModels if (_bufferQueue.TryDequeue(out short[] buffer)) { StreamingIsBusy = true; - _sttClient.FeedAudioContent(buffer, Convert.ToUInt32(buffer.Length)); + _sttClient.FeedAudioContent(_sttStream, buffer, Convert.ToUInt32(buffer.Length)); StreamingIsBusy = false; } } @@ -386,7 +393,7 @@ namespace DeepSpeech.WPF.ViewModels { await Task.Delay(90); } - Transcription = _sttClient.FinishStream(); + Transcription = _sttClient.FinishStream(_sttStream); EnableStartRecord = true; } @@ -395,7 +402,7 @@ namespace DeepSpeech.WPF.ViewModels /// private void StartRecording() { - _sttClient.CreateStream(); + _sttStream =_sttClient.CreateStream(); _audioCapture.Start(); EnableStartRecord = false; EnableStopRecord = true;