-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0210060
Showing
11 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.vs/ | ||
bin/ | ||
obj/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Words Dictator | ||
|
||
To make word dictation easier. Windows only. | ||
|
||
## Screenshots | ||
|
||
![](img/2020-09-23-00-35-38.png) | ||
|
||
![](img/2020-09-23-00-36-01.png) | ||
|
||
## How to use | ||
|
||
Click every button and see what happens. | ||
|
||
## About the bad coding experiences | ||
|
||
This APP aims at rapid developing, thus the coding conventions like MVVM or MVC or even no hard-coding are not under consideration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26124.0 | ||
MinimumVisualStudioVersion = 15.0.26124.0 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DD22A3E1-61F6-460A-AE02-247DFDECFB27}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WordsDictator", "src\WordsDictator\WordsDictator.csproj", "{5CD83BC6-0079-4A25-9E15-917A54DBE2DA}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5CD83BC6-0079-4A25-9E15-917A54DBE2DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5CD83BC6-0079-4A25-9E15-917A54DBE2DA}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5CD83BC6-0079-4A25-9E15-917A54DBE2DA}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{5CD83BC6-0079-4A25-9E15-917A54DBE2DA}.Debug|x64.Build.0 = Debug|Any CPU | ||
{5CD83BC6-0079-4A25-9E15-917A54DBE2DA}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{5CD83BC6-0079-4A25-9E15-917A54DBE2DA}.Debug|x86.Build.0 = Debug|Any CPU | ||
{5CD83BC6-0079-4A25-9E15-917A54DBE2DA}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5CD83BC6-0079-4A25-9E15-917A54DBE2DA}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{5CD83BC6-0079-4A25-9E15-917A54DBE2DA}.Release|x64.ActiveCfg = Release|Any CPU | ||
{5CD83BC6-0079-4A25-9E15-917A54DBE2DA}.Release|x64.Build.0 = Release|Any CPU | ||
{5CD83BC6-0079-4A25-9E15-917A54DBE2DA}.Release|x86.ActiveCfg = Release|Any CPU | ||
{5CD83BC6-0079-4A25-9E15-917A54DBE2DA}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{5CD83BC6-0079-4A25-9E15-917A54DBE2DA} = {DD22A3E1-61F6-460A-AE02-247DFDECFB27} | ||
EndGlobalSection | ||
EndGlobal |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="WordsDictator.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:WordsDictator" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace WordsDictator | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Windows; | ||
|
||
[assembly:ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<Window x:Class="WordsDictator.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:WordsDictator" | ||
mc:Ignorable="d" | ||
Title="Words Dictator" Height="450" Width="800"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Name="headRow" Height="Auto"></RowDefinition> | ||
<RowDefinition Name="body"></RowDefinition> | ||
</Grid.RowDefinitions> | ||
|
||
<Grid Grid.Row="0"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition></ColumnDefinition> | ||
<ColumnDefinition></ColumnDefinition> | ||
<ColumnDefinition></ColumnDefinition> | ||
</Grid.ColumnDefinitions> | ||
<CheckBox Grid.Column="0" Name="checkBoxIsDeleteAfterSpoken">读完删除</CheckBox> | ||
<Button Grid.Column="1" Name="btnRefresh" Click="btnRefresh_Click"> | ||
<AccessText>刷新(_x)</AccessText> | ||
</Button> | ||
<Button Grid.Column="2" Name="btnSpeak" Click="btnSpeak_Click"> | ||
<AccessText>朗读(_c)</AccessText> | ||
</Button> | ||
</Grid> | ||
<Grid Grid.Row="1"> | ||
<TabControl> | ||
<TabItem Header="输出"> | ||
<Grid Background="#FFE5E5E5"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto"></RowDefinition> | ||
<RowDefinition></RowDefinition> | ||
</Grid.RowDefinitions> | ||
<ListBox Grid.Row="0" Name="listSpeechSources" MaxHeight="80" SelectionChanged="listSpeechSources_SelectionChanged"></ListBox> | ||
<TextBox Grid.Row="1" Name="textBoxOutput" AcceptsReturn="True"></TextBox> | ||
</Grid> | ||
</TabItem> | ||
<TabItem Header="输入"> | ||
<Grid Background="#FFE5E5E5"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition></RowDefinition> | ||
<RowDefinition Height="Auto"></RowDefinition> | ||
</Grid.RowDefinitions> | ||
<TextBox Grid.Row="0" Name="textBoxInput" AcceptsReturn="True"></TextBox> | ||
<Grid Grid.Row="1"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition></ColumnDefinition> | ||
<ColumnDefinition></ColumnDefinition> | ||
</Grid.ColumnDefinitions> | ||
<Button Grid.Column="0" Name="btnLoadInput" Click="btnLoadInput_Click">Load</Button> | ||
<Button Grid.Column="1" Name="btnSaveInput" Click="btnSaveInput_Click">Save</Button> | ||
</Grid> | ||
</Grid> | ||
</TabItem> | ||
<TabItem Header="白板"> | ||
<Grid Background="#FFE5E5E5"> | ||
<TextBox Grid.Row="0" AcceptsReturn="True"></TextBox> | ||
</Grid> | ||
</TabItem> | ||
</TabControl> | ||
</Grid> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Speech.Synthesis; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Automation.Peers; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace WordsDictator | ||
{ | ||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
private readonly SpeechSynthesizer speech = new SpeechSynthesizer(); | ||
private readonly Random random = new Random(); | ||
private const string voiceIndexPath = "./voiceIndex.txt"; | ||
private const string inputTextPath = "./input.txt"; | ||
|
||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
|
||
foreach (var voice in this.speech.GetInstalledVoices()) | ||
{ | ||
listSpeechSources.Items.Add(voice.VoiceInfo.Description); | ||
} | ||
LoadTextBoxInput(); | ||
LoadVoiceIndex(); | ||
} | ||
|
||
private void btnRefresh_Click(object sender, RoutedEventArgs e) | ||
{ | ||
string[] words = textBoxInput.Text.Split(new char[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); | ||
if (words.Length <= 0) | ||
{ | ||
return; | ||
} | ||
int selectedIndex = random.Next(0, words.Length); | ||
string selectedWord = words[selectedIndex]; | ||
textBoxOutput.Text = selectedWord; | ||
SpeakTextBoxOutputText(); | ||
if (checkBoxIsDeleteAfterSpoken.IsChecked.Value) | ||
{ | ||
string pattern = $"(?<=[\n\r ]|^){selectedWord}(?=[\n\r ]|$)"; | ||
textBoxInput.Text = Regex.Replace(textBoxInput.Text, pattern, ""); | ||
} | ||
} | ||
|
||
private void btnSpeak_Click(object sender, RoutedEventArgs e) | ||
{ | ||
SpeakTextBoxOutputText(); | ||
} | ||
|
||
private void SpeakTextBoxOutputText() | ||
{ | ||
if (listSpeechSources.SelectedIndex < 0) | ||
{ | ||
MessageBox.Show("Please select a voice from the listbox", "Warming"); | ||
return; | ||
} | ||
var selectedVoice = this.speech.GetInstalledVoices()[listSpeechSources.SelectedIndex]; | ||
this.speech.SelectVoice(selectedVoice.VoiceInfo.Name); | ||
this.speech.SpeakAsync(textBoxOutput.Text); | ||
} | ||
|
||
private void btnSaveInput_Click(object sender, RoutedEventArgs e) | ||
{ | ||
SaveTextBoxInput(); | ||
} | ||
|
||
private void btnLoadInput_Click(object sender, RoutedEventArgs e) | ||
{ | ||
LoadTextBoxInput(); | ||
} | ||
|
||
private void listSpeechSources_SelectionChanged(object sender, RoutedEventArgs e) | ||
{ | ||
SaveSelectedVoiceIndex(); | ||
} | ||
|
||
private void SaveTextBoxInput() | ||
{ | ||
File.WriteAllText(inputTextPath, textBoxInput.Text); | ||
} | ||
|
||
private void LoadTextBoxInput() | ||
{ | ||
if (!File.Exists(inputTextPath)) | ||
{ | ||
return; | ||
} | ||
textBoxInput.Text = File.ReadAllText(inputTextPath); | ||
} | ||
|
||
private void SaveSelectedVoiceIndex() | ||
{ | ||
File.WriteAllText(voiceIndexPath, listSpeechSources.SelectedIndex.ToString()); | ||
} | ||
|
||
private void LoadVoiceIndex() | ||
{ | ||
if (!File.Exists(voiceIndexPath)) | ||
{ | ||
return; | ||
} | ||
listSpeechSources.SelectedIndex = int.Parse(File.ReadAllText(voiceIndexPath)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net472</TargetFramework> | ||
<UseWPF>true</UseWPF> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="System.Speech" /> | ||
</ItemGroup> | ||
|
||
</Project> |