Skip to content

Commit

Permalink
Add key speech on key action buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxhy committed Jul 5, 2024
1 parent d6e9d73 commit 4dd9636
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions KeyManager.Library.UI/KeyActionButtonsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<Button x:Name="btnPrint" Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}" Click="BtnPrint_Click" Width="24" Height="24" ToolTip="{x:Static properties:Resources.KeyExportPrint}" Margin="3">
<materialDesign:PackIcon Kind="Printer" Height="16" Width="16"/>
</Button>
<Button x:Name="btnSpeech" Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}" Click="BtnSpeech_Click" Width="24" Height="24" ToolTip="{x:Static properties:Resources.KeyExportSpeech}" Margin="3">
<materialDesign:PackIcon Kind="TextToSpeech" Height="16" Width="16"/>
</Button>
</StackPanel>
</materialDesign:PopupBox>
</StackPanel>
Expand Down
22 changes: 22 additions & 0 deletions KeyManager.Library.UI/KeyActionButtonsControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Leosac.KeyManager.Library.KeyStore;
using Leosac.KeyManager.Library.UI.Domain;
using Microsoft.Win32;
using System.Speech.Synthesis;
using System.Windows;
using System.Windows.Controls;

Expand Down Expand Up @@ -125,5 +126,26 @@ private void BtnPrint_Click(object sender, RoutedEventArgs e)
printDialog.PrintVisual(control, "Leosac Key Manager - Key Printing");
}
}

private void BtnSpeech_Click(object sender, RoutedEventArgs e)
{
var key = Key.GetAggregatedValueAsString();
Task.Run(() =>
{
var promptBuilder = new PromptBuilder();
var promptStyle = new PromptStyle
{
Volume = PromptVolume.Default,
Rate = PromptRate.ExtraSlow
};
promptBuilder.StartStyle(promptStyle);
promptBuilder.AppendTextWithHint(key, SayAs.SpellOut);
promptBuilder.EndStyle();
using var synthesizer = new SpeechSynthesizer();
synthesizer.SetOutputToDefaultAudioDevice();
synthesizer.Speak(promptBuilder);
});
}
}
}
1 change: 1 addition & 0 deletions KeyManager.Library.UI/KeyManager.Library.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<PackageReference Include="Net.Codecrete.QrCodeGenerator" Version="2.0.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SkiaSharp" Version="2.88.8" />
<PackageReference Include="System.Speech" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@
<data name="KeyExportPrint" xml:space="preserve">
<value>Export / Impression d'une clé</value>
</data>
<data name="KeyExportSpeech" xml:space="preserve">
<value>Dicter oralement</value>
</data>
<data name="KeyGeneration" xml:space="preserve">
<value>Génération locale d'une clé</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@
<data name="KeyExportPrint" xml:space="preserve">
<value>Key Export / Print</value>
</data>
<data name="KeyExportSpeech" xml:space="preserve">
<value>Speech</value>
</data>
<data name="KeyGeneration" xml:space="preserve">
<value>Local Key Generation</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions KeyManager.Setup/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@
<Component Id="SkiaSharpComponent">
<File Id="___var.SkiaSharp.dll_" Source="$(var.KeyManager.TargetDir)\SkiaSharp.dll" />
</Component>
<Component Id="SystemSpeechComponent">
<File Id="___var.System.Speech.dll_" Source="$(var.KeyManager.TargetDir)\System.Speech.dll" />
</Component>
<Component Id="WpfAppComponent">
<File Id="___var.WpfApp.dll_" Source="$(var.KeyManager.TargetDir)\WpfApp.dll" />
</Component>
Expand Down

0 comments on commit 4dd9636

Please sign in to comment.