feat(speech): Add text-to-speech function

dev_split_view_vm
DESKTOP-3BO4HSG\ksat 2 years ago
parent 7eb659266c
commit dd84d176f9

@ -30,6 +30,7 @@
- [x] 添加开机自启
- [x] 添加亮/暗主题
- [x] 添加 UI 设置缓存(用户目录下 `AppData\Local\STranslate`)
- [x] 添加文本转语音
- [ ] 添加 OCR 翻译
- [ ] 添加翻译记录缓存功能

Binary file not shown.

@ -71,6 +71,9 @@
<StackPanel Orientation="Horizontal"
Margin="10,5"
VerticalAlignment="Bottom">
<Button Template="{DynamicResource ButtonTemplateSpeak}"
Visibility="{Binding InputTxt,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding SourceSpeakCmd}"/>
<Button Template="{DynamicResource ButtonTemplate}"
Visibility="{Binding InputTxt,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopyInputCmd}"/>
@ -124,6 +127,9 @@
<StackPanel Orientation="Horizontal"
Margin="10,5"
VerticalAlignment="Bottom">
<Button Template="{DynamicResource ButtonTemplateSpeak}"
Visibility="{Binding OutputTxt,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding TargetSpeakCmd}"/>
<!--普通复制-->
<Button Template="{DynamicResource ButtonTemplate}"
Visibility="{Binding OutputTxt,Converter={StaticResource String2VisibilityConverter}}"

@ -47,6 +47,6 @@ using System.Windows;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.3.0")]
[assembly: AssemblyFileVersion("0.1.3.0")]
[assembly: AssemblyVersion("0.1.4.0")]
[assembly: AssemblyFileVersion("0.1.4.0")]
[assembly: Guid("CE252DD8-179F-4544-9989-453F5DEA378D")]

@ -19,7 +19,7 @@ namespace STranslate.Properties {
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {

@ -62,6 +62,7 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Speech" />
<Reference Include="System.Web" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />

@ -81,6 +81,29 @@
</ControlTemplate.Triggers>
</ControlTemplate>
<!--speak-->
<ControlTemplate x:Key="ButtonTemplateSpeak" TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Margin="0,0,5,0"
Padding="4"
MaxHeight="25">
<TextBlock Style="{StaticResource IconStyle}"
FontSize="17"
VerticalAlignment="Center"
Text="&#xe610;"
Foreground="WhiteSmoke"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#47484c"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#35333c"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!--普通复制-->
<ControlTemplate x:Key="ButtonTemplate" TargetType="Button">
<Border x:Name="border"

@ -81,6 +81,29 @@
</ControlTemplate.Triggers>
</ControlTemplate>
<!--speak-->
<ControlTemplate x:Key="ButtonTemplateSpeak" TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Margin="0,0,5,0"
Padding="4"
MaxHeight="25">
<TextBlock Style="{StaticResource IconStyle}"
FontSize="17"
VerticalAlignment="Center"
Text="&#xe610;"
Foreground="#515151"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#dddddd"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!--普通复制-->
<ControlTemplate x:Key="ButtonTemplate" TargetType="Button">
<Border x:Name="border"

@ -11,6 +11,7 @@ using System.Windows.Media;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
using STranslate.Util;
using System.Speech.Synthesis;
namespace STranslate.ViewModel
{
@ -28,6 +29,16 @@ namespace STranslate.ViewModel
InputCombo = LanguageEnumDict.Keys.ToList();
OutputCombo = LanguageEnumDict.Keys.ToList();
//source speak
SourceSpeakCmd = new RelayCommand((_) => true, (_) =>
{
_Speech.SpeakAsync(InputTxt);
});
//target speak
TargetSpeakCmd = new RelayCommand((_) => true, (_) =>
{
_Speech.SpeakAsync(OutputTxt);
});
//复制输入
CopyInputCmd = new RelayCommand((_) => true, (_) =>
{
@ -233,12 +244,15 @@ namespace STranslate.ViewModel
public void Dispose()
{
_Speech.Dispose();
WriteConfig();
}
#endregion handle
#region Params
private string translateResp;
public ICommand SourceSpeakCmd { get; private set; }
public ICommand TargetSpeakCmd { get; private set; }
public ICommand TranslateCmd { get; private set; }
public ICommand CopyInputCmd { get; private set; }
public ICommand CopyResultCmd { get; private set; }
@ -300,6 +314,12 @@ namespace STranslate.ViewModel
private Server _SelectedTranslationInterface;
public Server SelectedTranslationInterface { get => _SelectedTranslationInterface; set => UpdateProperty(ref _SelectedTranslationInterface, value); }
private static Dictionary<string, LanguageEnum> LanguageEnumDict { get => Util.Util.GetEnumList<LanguageEnum>(); }
/// <summary>
/// 语音
/// </summary>
private static readonly SpeechSynthesizer _Speech = new SpeechSynthesizer();
private static readonly string _ThemeDark = "pack://application:,,,/STranslate;component/Style/Dark.xaml";
private static readonly string _ThemeDefault = "pack://application:,,,/STranslate;component/Style/Default.xaml";
#endregion Params

Loading…
Cancel
Save