Skip to content

Commit

Permalink
Merge pull request mozilla#2525 from carlfm01/wpf-mvvm
Browse files Browse the repository at this point in the history
Move WPF example to MVVM
  • Loading branch information
lissyx authored Nov 13, 2019
2 parents c593564 + 42e5330 commit f18643b
Show file tree
Hide file tree
Showing 7 changed files with 558 additions and 315 deletions.
39 changes: 33 additions & 6 deletions examples/net_framework/DeepSpeechWPF/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using CommonServiceLocator;
using DeepSpeech.WPF.ViewModels;
using DeepSpeechClient.Interfaces;
using GalaSoft.MvvmLight.Ioc;
using System.Windows;

namespace DeepSpeechWPF
Expand All @@ -13,5 +11,34 @@ namespace DeepSpeechWPF
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

const int BEAM_WIDTH = 500;

//Register instance of DeepSpeech
DeepSpeechClient.DeepSpeech deepSpeechClient = new DeepSpeechClient.DeepSpeech();
try
{
deepSpeechClient.CreateModel("output_graph.pbmm", BEAM_WIDTH);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
Current.Shutdown();
}

SimpleIoc.Default.Register<IDeepSpeech>(() => deepSpeechClient);
SimpleIoc.Default.Register<MainWindowViewModel>();
}

protected override void OnExit(ExitEventArgs e)
{
base.OnExit(e);
//Dispose instance of DeepSpeech
ServiceLocator.Current.GetInstance<IDeepSpeech>()?.Dispose();
}
}
}
23 changes: 23 additions & 0 deletions examples/net_framework/DeepSpeechWPF/DeepSpeech.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,36 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="AsyncAwaitBestPractices, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\AsyncAwaitBestPractices.3.1.0\lib\netstandard1.0\AsyncAwaitBestPractices.dll</HintPath>
</Reference>
<Reference Include="AsyncAwaitBestPractices.MVVM, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\AsyncAwaitBestPractices.MVVM.3.1.0\lib\netstandard1.0\AsyncAwaitBestPractices.MVVM.dll</HintPath>
</Reference>
<Reference Include="CommonServiceLocator, Version=2.0.2.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>packages\CommonServiceLocator.2.0.2\lib\net45\CommonServiceLocator.dll</HintPath>
</Reference>
<Reference Include="CSCore, Version=1.2.1.2, Culture=neutral, PublicKeyToken=5a08f2b6f4415dea, processorArchitecture=MSIL">
<HintPath>packages\CSCore.1.2.1.2\lib\net35-client\CSCore.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight, Version=5.4.1.0, Culture=neutral, PublicKeyToken=e7570ab207bcb616, processorArchitecture=MSIL">
<HintPath>packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight.Extras, Version=5.4.1.0, Culture=neutral, PublicKeyToken=669f0b5e8f868abf, processorArchitecture=MSIL">
<HintPath>packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.Extras.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight.Platform, Version=5.4.1.0, Culture=neutral, PublicKeyToken=5f873c45e98af8a1, processorArchitecture=MSIL">
<HintPath>packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.Platform.dll</HintPath>
</Reference>
<Reference Include="NAudio, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\NAudio.1.9.0\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\MvvmLightLibs.5.4.1.1\lib\net45\System.Windows.Interactivity.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand All @@ -67,6 +88,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ViewModels\MainWindowViewModel.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -75,6 +97,7 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="ViewModels\BindableBase.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down
53 changes: 22 additions & 31 deletions examples/net_framework/DeepSpeechWPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
<RowDefinition />
</Grid.RowDefinitions>
<TextBox
x:Name="txtResult"
Grid.Row="1"
Margin="10,36,10,10"
FontSize="16px"
Text=""
Text="{Binding Transcription, Mode=OneWay}"
TextWrapping="Wrap" />
<Label
Grid.Row="1"
Expand All @@ -34,78 +33,70 @@
VerticalAlignment="Top"
Content="Select an audio file to transcript:" />
<TextBox
x:Name="txtFileName"
Height="23"
Margin="10,41,10,0"
VerticalAlignment="Top"
Text=""
Text="{Binding AudioFilePath, Mode=TwoWay}"
TextWrapping="Wrap" />
<Button
x:Name="btnOpenFile"
Width="80"
Height="25"
Margin="10,69,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Click="BtnOpenFile_Click"
Content="Open file"
IsEnabled="False" />
Command="{Binding SelectFileCommand}"
Content="Open file" />
<Button
x:Name="btnEnableLM"
Width="82"
Height="25"
Margin="95,69,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Click="BtnEnableLM_Click"
Content="Enable LM"
IsEnabled="False" />
Command="{Binding EnableLanguageModelCommand}"
Content="Enable LM" />
<Button
x:Name="btnTranscript"
Width="75"
Height="25"
Margin="182,69,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Click="BtnTranscript_Click"
Content="Transcript"
IsEnabled="False" />
Command="{Binding InferenceFromFileCommand}"
Content="Transcript" />
<Label
x:Name="lblStatus"
Height="30"
Margin="10,192,10,0"
Margin="10,99,10,0"
VerticalAlignment="Top"
Content="" />
Content="{Binding StatusMessage, Mode=OneWay}" />
<Label
Height="26"
Margin="10,119,10,0"
Margin="10,158,10,0"
VerticalAlignment="Top"
Content="Select an audio input:" />
<ComboBox
x:Name="cbxAudioInputs"
Height="23"
Margin="20,150,186,0"
Margin="20,189,186,0"
VerticalAlignment="Top"
SelectionChanged="CbxAudioInputs_SelectionChanged" />
DisplayMemberPath="FriendlyName"
ItemsSource="{Binding AvailableRecordDevices, Mode=TwoWay}"
SelectedIndex="0"
SelectedItem="{Binding SelectedDevice, Mode=TwoWay}" />
<Button
x:Name="btnStartRecording"
Width="91"
Height="23"
Margin="0,0,90,49"
Margin="0,0,90,10"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Click="BtnStartRecording_Click"
Command="{Binding StartRecordingCommand}"
Content="Record"
IsEnabled="False" />
IsEnabled="{Binding EnableStartRecord, Mode=OneWay}" />
<Button
x:Name="btnStopRecording"
Width="75"
Height="23"
Margin="0,0,10,49"
Margin="0,0,10,10"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Click="BtnStopRecording_Click"
Command="{Binding StopRecordingCommand}"
Content="Stop"
IsEnabled="False" />
IsEnabled="{Binding EnableStopRecord, Mode=OneWay}" />
</Grid>
</Window>
Loading

0 comments on commit f18643b

Please sign in to comment.