Skip to content

Commit 2cf2439

Browse files
lab13
1 parent 6d178a9 commit 2cf2439

13 files changed

+465
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.31101.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kinect2SampleSpeech", "Kinect2SampleSpeech\Kinect2SampleSpeech.csproj", "{C0661BEF-6F7F-4179-BD18-69381D0CEF77}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{C0661BEF-6F7F-4179-BD18-69381D0CEF77}.Debug|x64.ActiveCfg = Debug|x64
17+
{C0661BEF-6F7F-4179-BD18-69381D0CEF77}.Debug|x64.Build.0 = Debug|x64
18+
{C0661BEF-6F7F-4179-BD18-69381D0CEF77}.Debug|x64.Deploy.0 = Debug|x64
19+
{C0661BEF-6F7F-4179-BD18-69381D0CEF77}.Debug|x86.ActiveCfg = Debug|x64
20+
{C0661BEF-6F7F-4179-BD18-69381D0CEF77}.Release|x64.ActiveCfg = Release|x64
21+
{C0661BEF-6F7F-4179-BD18-69381D0CEF77}.Release|x64.Build.0 = Release|x64
22+
{C0661BEF-6F7F-4179-BD18-69381D0CEF77}.Release|x64.Deploy.0 = Release|x64
23+
{C0661BEF-6F7F-4179-BD18-69381D0CEF77}.Release|x86.ActiveCfg = Release|x64
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Application
2+
x:Class="Kinect2SampleSpeech.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:Kinect2SampleSpeech">
6+
7+
</Application>
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices.WindowsRuntime;
6+
using Windows.ApplicationModel;
7+
using Windows.ApplicationModel.Activation;
8+
using Windows.Foundation;
9+
using Windows.Foundation.Collections;
10+
using Windows.UI.Xaml;
11+
using Windows.UI.Xaml.Controls;
12+
using Windows.UI.Xaml.Controls.Primitives;
13+
using Windows.UI.Xaml.Data;
14+
using Windows.UI.Xaml.Input;
15+
using Windows.UI.Xaml.Media;
16+
using Windows.UI.Xaml.Navigation;
17+
18+
// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
19+
20+
namespace Kinect2SampleSpeech
21+
{
22+
/// <summary>
23+
/// Provides application-specific behavior to supplement the default Application class.
24+
/// </summary>
25+
sealed partial class App : Application
26+
{
27+
/// <summary>
28+
/// Initializes the singleton application object. This is the first line of authored code
29+
/// executed, and as such is the logical equivalent of main() or WinMain().
30+
/// </summary>
31+
public App()
32+
{
33+
this.InitializeComponent();
34+
this.Suspending += OnSuspending;
35+
}
36+
37+
/// <summary>
38+
/// Invoked when the application is launched normally by the end user. Other entry points
39+
/// will be used such as when the application is launched to open a specific file.
40+
/// </summary>
41+
/// <param name="e">Details about the launch request and process.</param>
42+
protected override void OnLaunched(LaunchActivatedEventArgs e)
43+
{
44+
45+
#if DEBUG
46+
if (System.Diagnostics.Debugger.IsAttached)
47+
{
48+
this.DebugSettings.EnableFrameRateCounter = true;
49+
}
50+
#endif
51+
52+
Frame rootFrame = Window.Current.Content as Frame;
53+
54+
// Do not repeat app initialization when the Window already has content,
55+
// just ensure that the window is active
56+
if (rootFrame == null)
57+
{
58+
// Create a Frame to act as the navigation context and navigate to the first page
59+
rootFrame = new Frame();
60+
// Set the default language
61+
rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
62+
63+
rootFrame.NavigationFailed += OnNavigationFailed;
64+
65+
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
66+
{
67+
//TODO: Load state from previously suspended application
68+
}
69+
70+
// Place the frame in the current Window
71+
Window.Current.Content = rootFrame;
72+
}
73+
74+
if (rootFrame.Content == null)
75+
{
76+
// When the navigation stack isn't restored navigate to the first page,
77+
// configuring the new page by passing required information as a navigation
78+
// parameter
79+
rootFrame.Navigate(typeof(MainPage), e.Arguments);
80+
}
81+
// Ensure the current window is active
82+
Window.Current.Activate();
83+
}
84+
85+
/// <summary>
86+
/// Invoked when Navigation to a certain page fails
87+
/// </summary>
88+
/// <param name="sender">The Frame which failed navigation</param>
89+
/// <param name="e">Details about the navigation failure</param>
90+
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
91+
{
92+
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
93+
}
94+
95+
/// <summary>
96+
/// Invoked when application execution is being suspended. Application state is saved
97+
/// without knowing whether the application will be terminated or resumed with the contents
98+
/// of memory still intact.
99+
/// </summary>
100+
/// <param name="sender">The source of the suspend request.</param>
101+
/// <param name="e">Details about the suspend request.</param>
102+
private void OnSuspending(object sender, SuspendingEventArgs e)
103+
{
104+
var deferral = e.SuspendingOperation.GetDeferral();
105+
//TODO: Save application state and stop any background activity
106+
deferral.Complete();
107+
}
108+
}
109+
}
Loading
Loading
Loading
Loading
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" 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>{C0661BEF-6F7F-4179-BD18-69381D0CEF77}</ProjectGuid>
8+
<OutputType>AppContainerExe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Kinect2SampleSpeech</RootNamespace>
11+
<AssemblyName>Kinect2SampleSpeech</AssemblyName>
12+
<DefaultLanguage>en-US</DefaultLanguage>
13+
<TargetPlatformVersion>8.1</TargetPlatformVersion>
14+
<MinimumVisualStudioVersion>12</MinimumVisualStudioVersion>
15+
<FileAlignment>512</FileAlignment>
16+
<ProjectTypeGuids>{BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
17+
<PackageCertificateKeyFile>Kinect2SampleSpeech_TemporaryKey.pfx</PackageCertificateKeyFile>
18+
</PropertyGroup>
19+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
20+
<DebugSymbols>true</DebugSymbols>
21+
<OutputPath>bin\x64\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_APP</DefineConstants>
23+
<NoWarn>;2008</NoWarn>
24+
<DebugType>full</DebugType>
25+
<PlatformTarget>x64</PlatformTarget>
26+
<UseVSHostingProcess>false</UseVSHostingProcess>
27+
<ErrorReport>prompt</ErrorReport>
28+
<Prefer32Bit>true</Prefer32Bit>
29+
</PropertyGroup>
30+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
31+
<OutputPath>bin\x64\Release\</OutputPath>
32+
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_APP</DefineConstants>
33+
<Optimize>true</Optimize>
34+
<NoWarn>;2008</NoWarn>
35+
<DebugType>pdbonly</DebugType>
36+
<PlatformTarget>x64</PlatformTarget>
37+
<UseVSHostingProcess>false</UseVSHostingProcess>
38+
<ErrorReport>prompt</ErrorReport>
39+
<Prefer32Bit>true</Prefer32Bit>
40+
</PropertyGroup>
41+
<ItemGroup>
42+
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
43+
<SDKReference Include="Bing.Speech, Version=1.1">
44+
<Name>Bing.Speech</Name>
45+
</SDKReference>
46+
<SDKReference Include="Microsoft.VCLibs, version=12.0">
47+
<Name>Microsoft Visual C++ 2013 Runtime Package for Windows</Name>
48+
</SDKReference>
49+
</ItemGroup>
50+
<ItemGroup>
51+
<Compile Include="App.xaml.cs">
52+
<DependentUpon>App.xaml</DependentUpon>
53+
</Compile>
54+
<Compile Include="MainPage.xaml.cs">
55+
<DependentUpon>MainPage.xaml</DependentUpon>
56+
</Compile>
57+
<Compile Include="Properties\AssemblyInfo.cs" />
58+
</ItemGroup>
59+
<ItemGroup>
60+
<AppxManifest Include="Package.appxmanifest">
61+
<SubType>Designer</SubType>
62+
</AppxManifest>
63+
<None Include="Kinect2SampleSpeech_TemporaryKey.pfx" />
64+
</ItemGroup>
65+
<ItemGroup>
66+
<Content Include="Assets\Logo.scale-100.png" />
67+
<Content Include="Assets\SmallLogo.scale-100.png" />
68+
<Content Include="Assets\SplashScreen.scale-100.png" />
69+
<Content Include="Assets\StoreLogo.scale-100.png" />
70+
</ItemGroup>
71+
<ItemGroup>
72+
<ApplicationDefinition Include="App.xaml">
73+
<Generator>MSBuild:Compile</Generator>
74+
<SubType>Designer</SubType>
75+
</ApplicationDefinition>
76+
<Page Include="MainPage.xaml">
77+
<Generator>MSBuild:Compile</Generator>
78+
<SubType>Designer</SubType>
79+
</Page>
80+
</ItemGroup>
81+
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '12.0' ">
82+
<VisualStudioVersion>12.0</VisualStudioVersion>
83+
</PropertyGroup>
84+
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
85+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
86+
Other similar extension points exist, see Microsoft.Common.targets.
87+
<Target Name="BeforeBuild">
88+
</Target>
89+
<Target Name="AfterBuild">
90+
</Target>
91+
-->
92+
</Project>
Binary file not shown.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Page
2+
x:Class="Kinect2SampleSpeech.MainPage"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:Kinect2SampleSpeech"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d">
9+
<Page.Resources>
10+
<Style TargetType="TextBlock">
11+
<Setter Property="FontSize" Value="15"/>
12+
<Setter Property="Margin" Value="15"/>
13+
</Style>
14+
</Page.Resources>
15+
16+
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
17+
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
18+
<Button x:Name="StartRecButton"
19+
Margin="20"
20+
Click="StartRecButton_Click">Start Recording</Button>
21+
<TextBlock x:Name="CaptureStateTextBlock"/>
22+
<TextBlock x:Name="VolumeTextBlock" />
23+
<TextBlock x:Name="IntermediateResultsTextBlock"/>
24+
<TextBlock x:Name="ConfidenceTextBlock"/>
25+
<TextBlock x:Name="FinalResultTextBlock"/>
26+
<TextBlock x:Name="AlternatesTextBlock"/>
27+
</StackPanel>
28+
</Grid>
29+
</Page>
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices.WindowsRuntime;
6+
using Windows.Foundation;
7+
using Windows.Foundation.Collections;
8+
using Windows.UI.Xaml;
9+
using Windows.UI.Xaml.Controls;
10+
using Windows.UI.Xaml.Controls.Primitives;
11+
using Windows.UI.Xaml.Data;
12+
using Windows.UI.Xaml.Input;
13+
using Windows.UI.Xaml.Media;
14+
using Windows.UI.Xaml.Navigation;
15+
using Bing.Speech;
16+
17+
namespace Kinect2SampleSpeech
18+
{
19+
20+
public sealed partial class MainPage : Page
21+
{
22+
private SpeechRecognizer speechRec;
23+
24+
public MainPage()
25+
{
26+
this.InitializeComponent();
27+
this.Loaded += MainPage_Loaded;
28+
}
29+
30+
void MainPage_Loaded(object sender, RoutedEventArgs e)
31+
{
32+
// Apply credentials from the Windows Azure Data Marketplace.
33+
var credentials = new SpeechAuthorizationParameters();
34+
credentials.ClientId = "YOUR CLIENT ID";
35+
credentials.ClientSecret = "YOUR CLIENT SECRET";
36+
37+
// Initialize the speech recognizer.
38+
speechRec = new SpeechRecognizer("en-US", credentials);
39+
40+
// Add speech recognition event handlers.
41+
speechRec.AudioCaptureStateChanged += speechRec_AudioCaptureStateChanged;
42+
speechRec.AudioLevelChanged += speechRec_AudioLevelChanged;
43+
speechRec.RecognizerResultReceived += speechRec_RecognizerResultReceived;
44+
}
45+
46+
void speechRec_RecognizerResultReceived(SpeechRecognizer sender, SpeechRecognitionResultReceivedEventArgs args)
47+
{
48+
if (args.Text == null) return;
49+
50+
IntermediateResultsTextBlock.Text = "IntermediateResults: " + args.Text;
51+
52+
if (args.Text.ToLower().Contains("cancel"))
53+
speechRec.RequestCancelOperation();
54+
else if (args.Text.ToLower().Contains("stop"))
55+
speechRec.StopListeningAndProcessAudio();
56+
}
57+
58+
void speechRec_AudioLevelChanged(SpeechRecognizer sender, SpeechRecognitionAudioLevelChangedEventArgs args)
59+
{
60+
VolumeTextBlock.Text = "Volume: "+ args.AudioLevel;
61+
}
62+
63+
void speechRec_AudioCaptureStateChanged(SpeechRecognizer sender, SpeechRecognitionAudioCaptureStateChangedEventArgs args)
64+
{
65+
CaptureStateTextBlock.Text = "Capture State: " + Enum.GetName(typeof(SpeechRecognizerAudioCaptureState), args.State);
66+
}
67+
68+
async private void StartRecButton_Click(object sender, RoutedEventArgs e)
69+
{
70+
// Prevent concurrent calls to an async method
71+
StartRecButton.IsEnabled = false;
72+
73+
// Reset all the text
74+
VolumeTextBlock.Text = "";
75+
CaptureStateTextBlock.Text = "";
76+
IntermediateResultsTextBlock.Text = "";
77+
ConfidenceTextBlock.Text = "";
78+
FinalResultTextBlock.Text = "";
79+
AlternatesTextBlock.Text = "";
80+
81+
// Use a try block because RecognizeSpeechToTextAsync depends on a web service which can throw exceptions.
82+
try
83+
{
84+
// Start speech recognition and await the result
85+
// As this is occuring, the RecognizerResultReceived will fire as the user is speaking.
86+
var result = await speechRec.RecognizeSpeechToTextAsync();
87+
88+
// Show the TextConfidence.
89+
ConfidenceTextBlock.Text = "Confidence: " + Enum.GetName(typeof(SpeechRecognitionConfidence), result.TextConfidence);
90+
91+
// Display the text.
92+
if (result.Text != null)
93+
{
94+
FinalResultTextBlock.Text = result.Text;
95+
}
96+
97+
// Fill a string with the alternate results.
98+
var alternates = result.GetAlternates(5);
99+
if (alternates.Count > 1)
100+
{
101+
string s = "";
102+
for (int i = 1; i < alternates.Count; i++)
103+
{
104+
s += "\n" + alternates[i].Text ;
105+
}
106+
AlternatesTextBlock.Text = "Alternates: " + s;
107+
}
108+
}
109+
catch (Exception ex)
110+
{
111+
// If there's an exception, show it instead of the Final Result.
112+
if (ex.GetType() != typeof(OperationCanceledException))
113+
{
114+
FinalResultTextBlock.Text = string.Format("{0}: {1}",
115+
ex.GetType().ToString(), ex.Message);
116+
}
117+
}
118+
119+
// Finished recording, allow recording again.
120+
StartRecButton.IsEnabled = true;
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)