Skip to content

Commit

Permalink
✨ 支持文本居中右对齐,修复崩溃
Browse files Browse the repository at this point in the history
  • Loading branch information
am009 committed Dec 12, 2023
1 parent b82fd18 commit ef3fc6d
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 20 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@
- 还需要更多功能?
- 请点击这里[创建issue](https://github.com/jxlpzqc/TMSpeech/issues/new)告诉我们!
- 如果你懂Windows/C#开发,欢迎提交pull request,开发的过程中遇到任何问题可以创建issue和我们讨论。

## Release 流程

- VisualStudio中右键项目,选择Publish,增加publish到文件夹的配置。
- 点击`Show all settings`修改Publish配置,
- `Configuration`为Release,
- 选择`Deployment mode``self-contained`
- 设置`target runtime``win-x64`
- 将模型文件夹复制到publish的文件夹内,重命名为models,打包为zip文件。
- 在开发电脑,和另外一台电脑上测试各种功能。
13 changes: 8 additions & 5 deletions TMSpeech.GUI/CmdSpeech.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace TMSpeech.GUI
{
class CmdSpeech : ISpecchRecognition
{
public IList<TextInfo> AllTexts { get; set; } = new List<TextInfo>();
public List<TextInfo> AllTexts { get; set; } = new List<TextInfo>();
public string CurrentText { get; set; }
public event EventHandler<SpeechEventArgs> TextChanged;
public event EventHandler<EventArgs> UpdateList;
public event EventHandler<SpeechEventArgs> UpdateList;

string ExecutablePath;
string Arguments;
Expand All @@ -36,15 +36,15 @@ public void Dispose()

public IList<TextInfo> GetAllTexts()
{
return AllTexts;
return new List<TextInfo>(AllTexts);
}

public void SetTextChangedHandler(EventHandler<SpeechEventArgs> handler)
{
this.TextChanged += handler;
}

public void SetUpdateListHandler(EventHandler<EventArgs> handler)
public void SetUpdateListHandler(EventHandler<SpeechEventArgs> handler)
{
this.UpdateList += handler;
}
Expand Down Expand Up @@ -98,7 +98,10 @@ public void Run()
}
catch { }
}
UpdateList?.Invoke(this, EventArgs.Empty);
UpdateList?.Invoke(this, new SpeechEventArgs()
{
Text = item,
});
buffer.Clear();
}
TextChanged?.Invoke(this, new SpeechEventArgs()
Expand Down
23 changes: 17 additions & 6 deletions TMSpeech.GUI/ConfigWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<d:Window.DataContext>
<local:Settings/>
</d:Window.DataContext>
<Window.Resources>
<local:EnumConverter x:Key="enumConverter"/>
</Window.Resources>
<DockPanel>
<StackPanel Margin="8" HorizontalAlignment="Right" DockPanel.Dock="Bottom" Orientation="Horizontal">
<Button Name="btnSave" Margin="4,0,4,0" Click="btnSave_Click">Save</Button>
Expand Down Expand Up @@ -52,7 +55,7 @@
<Setter Property="Margin" Value="5"/>
</Style>
</Grid.Resources>
<Label Grid.Row="0" Grid.Column="0">Application</Label>
<Label Grid.Row="0" Grid.Column="0">Audio Source</Label>
<ComboBox Grid.Row="0" Grid.Column="1" SelectedIndex="0">
<ComboBoxItem>System Internal Voice</ComboBoxItem>
</ComboBox>
Expand All @@ -69,16 +72,24 @@
<TextBox Grid.Row="4" Grid.Column="1" Text="{Binding FontSize}"></TextBox>

<Label Grid.Row="5" Grid.Column="0">Font Color</Label>
<p:ColorPicker Margin="4" Grid.Row="5" Grid.Column="1" SelectedColor="{Binding FontColor}"/>
<p:ColorPicker Margin="4" Grid.Row="5" Grid.Column="1" SelectedColor="{Binding FontColor}"/>

<Label Grid.Row="6" Grid.Column="0">Mouse Hover</Label>
<p:ColorPicker Margin="4" Grid.Row="6" Grid.Column="1" SelectedColor="{Binding HoverBgColor}"/>
<p:ColorPicker Margin="4" Grid.Row="6" Grid.Column="1" SelectedColor="{Binding HoverBgColor}"/>

<Label Grid.Row="7" Grid.Column="0">History Bg</Label>
<p:ColorPicker Margin="4" Grid.Row="7" Grid.Column="1" SelectedColor="{Binding ListBgColor}"/>
<p:ColorPicker Margin="4" Grid.Row="7" Grid.Column="1" SelectedColor="{Binding ListBgColor}"/>

<Label Grid.Row="8" Grid.Column="0">Text Alignment</Label>
<ComboBox Margin="4" Grid.Row="8" Grid.Column="1" SelectedIndex="{Binding TextAlign,Converter={StaticResource enumConverter}}">
<ComboBoxItem Content="Left"/>
<ComboBoxItem Content="Right"/>
<ComboBoxItem Content="Center"/>
<ComboBoxItem Content="Justify"/>
</ComboBox>

<Label Grid.Row="8" Grid.Column="0">Log Save</Label>
<TextBox Grid.Row="8" Grid.Column="1" Text="{Binding LogSave}"></TextBox>
<Label Grid.Row="9" Grid.Column="0">Log Save</Label>
<TextBox Grid.Row="9" Grid.Column="1" Text="{Binding LogSave}"></TextBox>


</Grid>
Expand Down
24 changes: 24 additions & 0 deletions TMSpeech.GUI/EnumConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace TMSpeech.GUI
{
public class EnumConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
return (int)value;
}

public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
return Enum.ToObject(targetType, value);
}
}
}
2 changes: 1 addition & 1 deletion TMSpeech.GUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<DockPanel>

<ScrollViewer DockPanel.Dock="Bottom" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<local:OutlinedTextBlock DockPanel.Dock="Bottom" x:Name="txtMain" IsHitTestVisible="True" FontWeight="ExtraBold" TextWrapping="Wrap" StrokeThickness="{DynamicResource StrokeSize}" Stroke="{DynamicResource StrokeBrush}" FontSize="{DynamicResource FontSize}" Fill="{DynamicResource FontBrush}" FontFamily="{DynamicResource FontFamily}">
<local:OutlinedTextBlock DockPanel.Dock="Bottom" x:Name="txtMain" IsHitTestVisible="True" FontWeight="ExtraBold" TextWrapping="Wrap" TextAlignment="{DynamicResource TextAlign}" StrokeThickness="{DynamicResource StrokeSize}" Stroke="{DynamicResource StrokeBrush}" FontSize="{DynamicResource FontSize}" Fill="{DynamicResource FontBrush}" FontFamily="{DynamicResource FontFamily}">
Wait for audio input...
</local:OutlinedTextBlock>
</ScrollViewer>
Expand Down
6 changes: 3 additions & 3 deletions TMSpeech.GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface ISpecchRecognition: IDisposable
{
IList<TextInfo> GetAllTexts();
void SetTextChangedHandler(EventHandler<SpeechEventArgs> handler);
void SetUpdateListHandler(EventHandler<EventArgs> handler);
void SetUpdateListHandler(EventHandler<SpeechEventArgs> handler);
void Run();
void Clear();
}
Expand Down Expand Up @@ -136,11 +136,11 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
_thread.Start();
}

private void _core_UpdateList(object sender, EventArgs e)
private void _core_UpdateList(object sender, SpeechEventArgs e)
{
Dispatcher.Invoke(() =>
{
listHistory.ItemsSource = _core.GetAllTexts();
listHistory.Items.Add(e.Text);
listHistory.Items.Refresh();
listHistory.SelectedIndex = listHistory.Items.Count - 1;
listHistory.ScrollIntoView(listHistory.SelectedItem);
Expand Down
14 changes: 14 additions & 0 deletions TMSpeech.GUI/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace TMSpeech.GUI
Expand Down Expand Up @@ -158,6 +159,19 @@ public double StrokeSize
}
}

private TextAlignment _textAlign;

[ApplyToResource]
public TextAlignment TextAlign
{
get => _textAlign;
set
{
_textAlign = value;
NotifyChange(x => x._textAlign);
}
}

private string _fontFamilyStr;

public string FontFamilyStr
Expand Down
13 changes: 8 additions & 5 deletions TMSpeech.GUI/SpeechCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ namespace TMSpeech.GUI
{
class SpeechCore : ISpecchRecognition
{
public IList<TextInfo> AllTexts { get; set; } = new List<TextInfo>();
public List<TextInfo> AllTexts { get; set; } = new List<TextInfo>();
public string CurrentText { get; set; }
public event EventHandler<SpeechEventArgs> TextChanged;
public event EventHandler<EventArgs> UpdateList;
public event EventHandler<SpeechEventArgs> UpdateList;

string Encoder;
string Decoder;
Expand Down Expand Up @@ -117,7 +117,10 @@ public void Run(string encoder, string decoder, string joiner, string tokens, st
}

recognizer.Reset(s);
UpdateList?.Invoke(this, EventArgs.Empty);
UpdateList?.Invoke(this, new SpeechEventArgs()
{
Text = item,
});
}
}
Thread.Sleep(20);
Expand Down Expand Up @@ -146,7 +149,7 @@ public void SetTextChangedHandler(EventHandler<SpeechEventArgs> handler)
this.TextChanged += handler;
}

public void SetUpdateListHandler(EventHandler<EventArgs> handler)
public void SetUpdateListHandler(EventHandler<SpeechEventArgs> handler)
{
this.UpdateList += handler;
}
Expand All @@ -158,7 +161,7 @@ public void Run()

public IList<TextInfo> GetAllTexts()
{
return AllTexts;
return new List<TextInfo>(AllTexts);
}
}
}

0 comments on commit ef3fc6d

Please sign in to comment.