init
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo3", "Demo3\Demo3.csproj", "{33D30437-2141-4BEE-B4DE-FBF5B01F7A8C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{33D30437-2141-4BEE-B4DE-FBF5B01F7A8C}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{33D30437-2141-4BEE-B4DE-FBF5B01F7A8C}.Debug|x86.Build.0 = Debug|x86
|
||||
{33D30437-2141-4BEE-B4DE-FBF5B01F7A8C}.Release|x86.ActiveCfg = Release|x86
|
||||
{33D30437-2141-4BEE-B4DE-FBF5B01F7A8C}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{33D30437-2141-4BEE-B4DE-FBF5B01F7A8C}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Demo3</RootNamespace>
|
||||
<AssemblyName>Demo3</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Research.Kinect, Version=1.0.0.45, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
|
||||
<Reference Include="Microsoft.Speech, Version=10.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>C:\Program Files\Microsoft Speech Platform SDK\Assembly\Microsoft.Speech.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SpeechToText.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Demo3
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
KinectWorkshop.SpeechToText stt = new KinectWorkshop.SpeechToText();
|
||||
stt.TextRecognized += new EventHandler<KinectWorkshop.SpeechToText.TextRecognizedArgs>(stt_TextRecognized);
|
||||
stt.Start();
|
||||
Console.ReadLine();
|
||||
stt.Stop();
|
||||
}
|
||||
|
||||
static void stt_TextRecognized(object sender, KinectWorkshop.SpeechToText.TextRecognizedArgs e)
|
||||
{
|
||||
Console.WriteLine(e.Verb);
|
||||
switch (e.Verb)
|
||||
{
|
||||
case KinectWorkshop.SpeechToText.Verbs.None:
|
||||
break;
|
||||
case KinectWorkshop.SpeechToText.Verbs.PreviousSlide:
|
||||
break;
|
||||
case KinectWorkshop.SpeechToText.Verbs.NextSlide:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die mit einer Assembly verknüpft sind.
|
||||
[assembly: AssemblyTitle("Demo3")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Demo3")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2011")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
|
||||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("1fd608c9-3dd2-4d4b-b7a0-c368ff56a377")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Microsoft.Research.Kinect.Audio;
|
||||
using Microsoft.Speech.AudioFormat;
|
||||
using Microsoft.Speech.Recognition;
|
||||
|
||||
namespace KinectWorkshop
|
||||
{
|
||||
public class SpeechToText
|
||||
{
|
||||
public enum Verbs
|
||||
{
|
||||
None = 0,
|
||||
PreviousSlide,
|
||||
NextSlide
|
||||
};
|
||||
|
||||
Dictionary<string, Verbs> SinglePhrases = new Dictionary<string, Verbs>()
|
||||
{
|
||||
{"previous slide", Verbs.PreviousSlide},
|
||||
{"next slide", Verbs.NextSlide}
|
||||
};
|
||||
|
||||
public class TextRecognizedArgs : EventArgs
|
||||
{
|
||||
public Verbs Verb { get; set; }
|
||||
public string Phrase { get; set; }
|
||||
public string Matched {get; set; }
|
||||
}
|
||||
|
||||
public event EventHandler<TextRecognizedArgs> TextRecognized;
|
||||
|
||||
private KinectAudioSource kinectSource;
|
||||
private SpeechRecognitionEngine sre;
|
||||
private const string RecognizerId = "SR_MS_en-US_Kinect_10.0";
|
||||
|
||||
public SpeechToText()
|
||||
{
|
||||
RecognizerInfo ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == RecognizerId).FirstOrDefault();
|
||||
if (ri == null)
|
||||
return;
|
||||
|
||||
sre = new SpeechRecognitionEngine(ri.Id);
|
||||
var singlePhrases = new Choices();
|
||||
foreach (var phrase in SinglePhrases)
|
||||
singlePhrases.Add(phrase.Key);
|
||||
|
||||
var g = new Grammar(new GrammarBuilder(singlePhrases));
|
||||
sre.LoadGrammar(g);
|
||||
sre.SpeechRecognized += sre_SpeechRecognized;
|
||||
sre.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(sre_SpeechRecognitionRejected);
|
||||
}
|
||||
|
||||
private void StartSST()
|
||||
{
|
||||
kinectSource = new KinectAudioSource();
|
||||
kinectSource.SystemMode = SystemMode.OptibeamArrayOnly;
|
||||
kinectSource.FeatureMode = true;
|
||||
kinectSource.AutomaticGainControl = false;
|
||||
kinectSource.MicArrayMode = MicArrayMode.MicArrayAdaptiveBeam;
|
||||
var kinectStream = kinectSource.Start();
|
||||
sre.SetInputToAudioStream(kinectStream, new SpeechAudioFormatInfo(
|
||||
EncodingFormat.Pcm, 16000, 16, 1,
|
||||
32000, 2, null));
|
||||
sre.RecognizeAsync(RecognizeMode.Multiple);
|
||||
|
||||
//const double alpha = 0.35;
|
||||
//double angle = 0.0;
|
||||
//while (true)
|
||||
//{
|
||||
// if (kinectSource.SoundSourcePositionConfidence > 0.5)
|
||||
// {
|
||||
// double a = alpha*kinectSource.SoundSourcePositionConfidence;
|
||||
// angle = (1 - a) * angle + a * kinectSource.SoundSourcePosition;
|
||||
// Console.WriteLine(angle + ":" + kinectSource.MicArrayBeamAngle);
|
||||
// }
|
||||
// System.Threading.Thread.Sleep(50);
|
||||
//}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
var t = new Thread(StartSST);
|
||||
t.Start();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (sre != null)
|
||||
{
|
||||
sre.RecognizeAsyncCancel();
|
||||
sre.RecognizeAsyncStop();
|
||||
kinectSource.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
void sre_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
|
||||
{
|
||||
var said = new TextRecognizedArgs();
|
||||
said.Verb = Verbs.None;
|
||||
said.Matched = "?";
|
||||
TextRecognized(new object(), said);
|
||||
Console.WriteLine("\nSpeech Rejected");
|
||||
}
|
||||
|
||||
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
|
||||
{
|
||||
if (TextRecognized == null)
|
||||
return;
|
||||
|
||||
var said = new TextRecognizedArgs();
|
||||
said.Verb = Verbs.None;
|
||||
said.Phrase = e.Result.Text;
|
||||
|
||||
bool found = false;
|
||||
foreach (var phrase in SinglePhrases)
|
||||
{
|
||||
if (e.Result.Text.Contains(phrase.Key))
|
||||
{
|
||||
said.Verb = phrase.Value;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return;
|
||||
|
||||
TextRecognized(new object(), said);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user