Skip to content

Commit 3ae5c3c

Browse files
committed
复现UWP客户端的语音识别应用
1 parent c159eb2 commit 3ae5c3c

15 files changed

+1065
-0
lines changed

.gitattributes

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain

ASRT_SpeechClient_WPF.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27703.2042
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASRT_SpeechClient_WPF", "ASRT_SpeechClient_WPF\ASRT_SpeechClient_WPF.csproj", "{3DDB5582-4F2A-46BA-A072-363E92E296B1}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{3DDB5582-4F2A-46BA-A072-363E92E296B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{3DDB5582-4F2A-46BA-A072-363E92E296B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{3DDB5582-4F2A-46BA-A072-363E92E296B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{3DDB5582-4F2A-46BA-A072-363E92E296B1}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {85D6E564-D20C-4180-A77A-D7EFA0C7EC89}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{3DDB5582-4F2A-46BA-A072-363E92E296B1}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>ASRT_SpeechClient_WPF</RootNamespace>
10+
<AssemblyName>ASRT_SpeechClient_WPF</AssemblyName>
11+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<WarningLevel>4</WarningLevel>
15+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<PlatformTarget>AnyCPU</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<PlatformTarget>AnyCPU</PlatformTarget>
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="System" />
38+
<Reference Include="System.Data" />
39+
<Reference Include="System.Xml" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Core" />
42+
<Reference Include="System.Xml.Linq" />
43+
<Reference Include="System.Data.DataSetExtensions" />
44+
<Reference Include="System.Net.Http" />
45+
<Reference Include="System.Xaml">
46+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
47+
</Reference>
48+
<Reference Include="WindowsBase" />
49+
<Reference Include="PresentationCore" />
50+
<Reference Include="PresentationFramework" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<ApplicationDefinition Include="App.xaml">
54+
<Generator>MSBuild:Compile</Generator>
55+
<SubType>Designer</SubType>
56+
</ApplicationDefinition>
57+
<Compile Include="SpeechRecognition.cs" />
58+
<Compile Include="WavRecorder.cs" />
59+
<Page Include="MainWindow.xaml">
60+
<Generator>MSBuild:Compile</Generator>
61+
<SubType>Designer</SubType>
62+
</Page>
63+
<Compile Include="App.xaml.cs">
64+
<DependentUpon>App.xaml</DependentUpon>
65+
<SubType>Code</SubType>
66+
</Compile>
67+
<Compile Include="MainWindow.xaml.cs">
68+
<DependentUpon>MainWindow.xaml</DependentUpon>
69+
<SubType>Code</SubType>
70+
</Compile>
71+
</ItemGroup>
72+
<ItemGroup>
73+
<Compile Include="Properties\AssemblyInfo.cs">
74+
<SubType>Code</SubType>
75+
</Compile>
76+
<Compile Include="Properties\Resources.Designer.cs">
77+
<AutoGen>True</AutoGen>
78+
<DesignTime>True</DesignTime>
79+
<DependentUpon>Resources.resx</DependentUpon>
80+
</Compile>
81+
<Compile Include="Properties\Settings.Designer.cs">
82+
<AutoGen>True</AutoGen>
83+
<DependentUpon>Settings.settings</DependentUpon>
84+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
85+
</Compile>
86+
<EmbeddedResource Include="Properties\Resources.resx">
87+
<Generator>ResXFileCodeGenerator</Generator>
88+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
89+
</EmbeddedResource>
90+
<None Include="Properties\Settings.settings">
91+
<Generator>SettingsSingleFileGenerator</Generator>
92+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
93+
</None>
94+
</ItemGroup>
95+
<ItemGroup>
96+
<None Include="App.config" />
97+
</ItemGroup>
98+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
99+
</Project>

ASRT_SpeechClient_WPF/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
</configuration>

ASRT_SpeechClient_WPF/App.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="ASRT_SpeechClient_WPF.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:ASRT_SpeechClient_WPF"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>

ASRT_SpeechClient_WPF/App.xaml.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace ASRT_SpeechClient_WPF
10+
{
11+
/// <summary>
12+
/// App.xaml 的交互逻辑
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}

ASRT_SpeechClient_WPF/MainWindow.xaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Window x:Class="ASRT_SpeechClient_WPF.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:ASRT_SpeechClient_WPF"
7+
mc:Ignorable="d"
8+
Title="ASRT_SpeechClient_WPF" Height="800" Width="1200" MinWidth="1200" MinHeight="800" Margin="0" WindowStartupLocation="CenterScreen">
9+
<Grid Background="#FF043CF7">
10+
<TextBox x:Name="text_note" HorizontalAlignment="Stretch" Margin="0,0,0,200" Text="" TextWrapping="Wrap" AcceptsReturn="True" VerticalAlignment="Stretch" BorderThickness="0,0,0,2" ScrollViewer.VerticalScrollBarVisibility="Auto" FontFamily="Microsoft YaHei" FontSize="108" Foreground="White" Background="#66FFFFFF" FontWeight="Bold"/>
11+
12+
<Button x:Name="btn_start_speech_input" Content="开始语音输入" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="100,0,0,50" Width="300" Height="120" Foreground="White" FontSize="36" Background="#99DDDDDD" Click="btn_start_speech_input_Click"/>
13+
<Button x:Name="btn_end_speech_input" Content="停止语音输入" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,50" Width="300" Height="120" Foreground="White" FontSize="36" Background="#99DDDDDD" Click="btn_end_speech_input_Click"/>
14+
<Button x:Name="btn_save_file" Content="保存文件" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,100,50" Width="300" Height="120" Foreground="White" FontSize="36" Background="#99DDDDDD" Click="btn_save_file_Click"/>
15+
<TextBox x:Name="MessageBox" HorizontalAlignment="Center" Height="100" Text=" 正在识别... " VerticalAlignment="Bottom" Width="400" Background="#66FFFFFF" FontSize="70" Foreground="White" FontFamily="Microsoft YaHei" IsReadOnly="True" Margin="0,0,0,180"/>
16+
17+
</Grid>
18+
</Window>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
using ailemon.asrt;
16+
17+
namespace ASRT_SpeechClient_WPF
18+
{
19+
/// <summary>
20+
/// MainWindow.xaml 的交互逻辑
21+
/// </summary>
22+
public partial class MainWindow : Window
23+
{
24+
SpeechRecognizer asr = new SpeechRecognizer();
25+
26+
public MainWindow()
27+
{
28+
InitializeComponent();
29+
30+
MessageBox.Visibility = Visibility.Collapsed;
31+
asr.OnReceiveText += SpeechRecognizer_OnReceiveText;
32+
}
33+
34+
private void btn_start_speech_input_Click(object sender, RoutedEventArgs e)
35+
{
36+
asr.Start();
37+
MessageBox.Visibility = Visibility.Visible;
38+
}
39+
40+
private void btn_end_speech_input_Click(object sender, RoutedEventArgs e)
41+
{
42+
asr.StopAsync();
43+
MessageBox.Visibility = Visibility.Collapsed;
44+
}
45+
46+
private async void btn_save_file_Click(object sender, RoutedEventArgs e)
47+
{
48+
text_note.Text += await asr.RecogniteFromFile("1.wav");
49+
50+
text_note.ScrollToEnd();
51+
}
52+
53+
private void SpeechRecognizer_OnReceiveText(object sender, string text)
54+
{
55+
//事件处理方法
56+
text_note.Text += text;
57+
text_note.ScrollToEnd();
58+
}
59+
}
60+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Reflection;
2+
using System.Resources;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
using System.Windows;
6+
7+
// 有关程序集的一般信息由以下
8+
// 控制。更改这些特性值可修改
9+
// 与程序集关联的信息。
10+
[assembly: AssemblyTitle("ASRT_SpeechClient_WPF")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("")]
14+
[assembly: AssemblyProduct("ASRT_SpeechClient_WPF")]
15+
[assembly: AssemblyCopyright("Copyright © 2018")]
16+
[assembly: AssemblyTrademark("")]
17+
[assembly: AssemblyCulture("")]
18+
19+
// 将 ComVisible 设置为 false 会使此程序集中的类型
20+
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
21+
//请将此类型的 ComVisible 特性设置为 true。
22+
[assembly: ComVisible(false)]
23+
24+
//若要开始生成可本地化的应用程序,请设置
25+
//.csproj 文件中的 <UICulture>CultureYouAreCodingWith</UICulture>
26+
//例如,如果您在源文件中使用的是美国英语,
27+
//使用的是美国英语,请将 <UICulture> 设置为 en-US。 然后取消
28+
//对以下 NeutralResourceLanguage 特性的注释。 更新
29+
//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
30+
31+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32+
33+
34+
[assembly: ThemeInfo(
35+
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
36+
//(未在页面中找到资源时使用,
37+
//或应用程序资源字典中找到时使用)
38+
ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
39+
//(未在页面中找到资源时使用,
40+
//、应用程序或任何主题专用资源字典中找到时使用)
41+
)]
42+
43+
44+
// 程序集的版本信息由下列四个值组成:
45+
//
46+
// 主版本
47+
// 次版本
48+
// 生成号
49+
// 修订号
50+
//
51+
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
52+
// 方法是按如下所示使用“*”: :
53+
// [assembly: AssemblyVersion("1.0.*")]
54+
[assembly: AssemblyVersion("1.0.0.0")]
55+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)