Speech_Recognition_using_Microsoft_SAPI
[
Front page
] [
New
|
List of pages
|
Search
|
Recent changes
|
Help
]
Start:
//
// Written by N.D.Khoa on 2012-04-22
//
Up:[[Tutorial]]
----
#contents
* Speech recognition using Microsoft SAPI [#o63dca14]
This section explains how to perform speech recognition i...
※ This sample is tested with Visual studio 2010 and windo...
** Install Microsoft speech SDK [#q579c66f]
Download and install Microsoft speech SDK from [[here>htt...
** Build sample speech recognition using Microsoft SAPI [...
*** Create Recognizer: [#rdb14941]
#highlight(c#){{
using System.Speech.Recognition;
...
// Recognition Engines
SpeechRecognitionEngine _speechRecognitionEngine;
...
// Creating speech Recognition engine
_speechRecognitionEngine= new SpeechRecognitionEngine();
...
}}
*** Add event handler: [#vf81deb6]
#highlight(c#){{
...
// The result will be processed in SpeechEngine_SpeechRe...
_speechRecognitionEngine.SpeechRecognized +=
new EventHandler<SpeechRecognizedEven...
...
}}
*** Create Grammar: [#fd5fd131]
#highlight(c#){{
...
GrammarBuilder CMD = new GrammarBuilder();
CMD.Append(new Choices("Please take a cup of",
"I need some",
"take a cup of"));
//Providence T. F. Green Internatinoal Airport
GrammarBuilder OBJ = new GrammarBuilder();
Choices OBJchoices = new Choices("coffee",
"tea",
"milk",
"hot water");
OBJ.Append(OBJchoices);
OBJ.Append(new SemanticResultValue("Object"));
CMD.Append(OBJ);
//Boston Logan Internatinoal Airport
GrammarBuilder CTRL = new GrammarBuilder();
Choices CTRLchoices = new Choices("go back",
"go ahead",
"turn left",
"turn right",
"stop");
CTRL.Append(CTRLchoices);
CTRL.Append(new SemanticResultValue("CTRL"));
// Final choices
Choices finalChoices = new Choices("Hi",
"Hello",
"What is your name",
"How are you",
"How are you today",
"How'r you",
"Are you ready");
finalChoices.Add(CMD);
finalChoices.Add(CTRL);
//Final Grammar
GrammarBuilder dialogGrammar = new GrammarBuilder();
dialogGrammar.Culture = culture;
dialogGrammar.Append(new SemanticResultKey("Dialog",final...
// Load grammar
_speechRecognitionEngine.LoadGrammar(dialogGrammar);
...
}}
*** Set input source for Recognizer: [#eb3310db]
#highlight(c#){{
...
// Set input to Default Audio device
_speechRecognitionEngine.SetInputToDefaultAudioDevice();
...
}}
*** Start recognize: [#b48271a3]
#highlight(c#){{
...
// start asynchronous recognizer
try
{
_speechRecognitionEngine.RecognizeAsync(RecognizeMode...
}
catch (InvalidOperationException e)
{
_isRecognizing = false;
LogLine("Failed");
LogLine(e.Message);
return false;
}
// start synchronous recognizer
try
{
_speechRecognitionEngine.Recognize();
}
catch (InvalidOperationException e)
{
LogLine(e.Message);
return false;
}
}}
** Send result text to an Agent in SIGverse [#b49c4788]
*** Import sigverse.dll [#afb97c89]
Follow this tutorial [[import DLL:http://www.sociointelli...
*** Send result text to SIGverse [#of8c83cf]
#highlight(c#){{
sbyte[] String2Sbytes(string text)
{
sbyte[] osb = new sbyte[text.Length];
byte[] b = Encoding.ASCII.GetBytes(text);
for (int i = 0; i < b.Length; i++)
{
osb[i] = (sbyte)b[i];
}
return osb;
}
void SendMessage2Agent(string hostname, string po...
{
MessageSender messageSender;
sbyte[] rs = String2Sbytes(message + "\0");
unsafe
{
sbyte[] _msgname = String2Sbytes("Microso...
fixed (sbyte* _mn = _msgname)
{
messageSender = new MessageSender(_mn);
fixed (sbyte* _hn = String2Sbytes(hos...
{
if (messageSender.connect(_hn, Co...
{
LogLine("Connected to [" + ho...
sbyte* a = stackalloc sbyte[r...
for (int i = 0; i < rs.Length...
{
a[i] = rs[i];
}
sbyte** _rs = &a;
sbyte[] agent = String2Sbytes...
fixed (sbyte* _agent = agent)
{
if (messageSender.sendto(...
{
LogLine("message [" +...
}
else
{
LogLine("error to sen...
}
}
}
else
{
LogLine("Can not connect to [...
}
}
}
}
}
// handle recognized event
void SpeechEngine_SpeechRecognized(object sender,...
{
...
// Send message to SIGverse's Agent here
SendMessage2Agent(_hostNameSIGverse.Text, _po...
...
}
}}
#highlight(end)
Up:[[Tutorial]] Previous:[[Samples/Communication...
#counter
End:
//
// Written by N.D.Khoa on 2012-04-22
//
Up:[[Tutorial]]
----
#contents
* Speech recognition using Microsoft SAPI [#o63dca14]
This section explains how to perform speech recognition i...
※ This sample is tested with Visual studio 2010 and windo...
** Install Microsoft speech SDK [#q579c66f]
Download and install Microsoft speech SDK from [[here>htt...
** Build sample speech recognition using Microsoft SAPI [...
*** Create Recognizer: [#rdb14941]
#highlight(c#){{
using System.Speech.Recognition;
...
// Recognition Engines
SpeechRecognitionEngine _speechRecognitionEngine;
...
// Creating speech Recognition engine
_speechRecognitionEngine= new SpeechRecognitionEngine();
...
}}
*** Add event handler: [#vf81deb6]
#highlight(c#){{
...
// The result will be processed in SpeechEngine_SpeechRe...
_speechRecognitionEngine.SpeechRecognized +=
new EventHandler<SpeechRecognizedEven...
...
}}
*** Create Grammar: [#fd5fd131]
#highlight(c#){{
...
GrammarBuilder CMD = new GrammarBuilder();
CMD.Append(new Choices("Please take a cup of",
"I need some",
"take a cup of"));
//Providence T. F. Green Internatinoal Airport
GrammarBuilder OBJ = new GrammarBuilder();
Choices OBJchoices = new Choices("coffee",
"tea",
"milk",
"hot water");
OBJ.Append(OBJchoices);
OBJ.Append(new SemanticResultValue("Object"));
CMD.Append(OBJ);
//Boston Logan Internatinoal Airport
GrammarBuilder CTRL = new GrammarBuilder();
Choices CTRLchoices = new Choices("go back",
"go ahead",
"turn left",
"turn right",
"stop");
CTRL.Append(CTRLchoices);
CTRL.Append(new SemanticResultValue("CTRL"));
// Final choices
Choices finalChoices = new Choices("Hi",
"Hello",
"What is your name",
"How are you",
"How are you today",
"How'r you",
"Are you ready");
finalChoices.Add(CMD);
finalChoices.Add(CTRL);
//Final Grammar
GrammarBuilder dialogGrammar = new GrammarBuilder();
dialogGrammar.Culture = culture;
dialogGrammar.Append(new SemanticResultKey("Dialog",final...
// Load grammar
_speechRecognitionEngine.LoadGrammar(dialogGrammar);
...
}}
*** Set input source for Recognizer: [#eb3310db]
#highlight(c#){{
...
// Set input to Default Audio device
_speechRecognitionEngine.SetInputToDefaultAudioDevice();
...
}}
*** Start recognize: [#b48271a3]
#highlight(c#){{
...
// start asynchronous recognizer
try
{
_speechRecognitionEngine.RecognizeAsync(RecognizeMode...
}
catch (InvalidOperationException e)
{
_isRecognizing = false;
LogLine("Failed");
LogLine(e.Message);
return false;
}
// start synchronous recognizer
try
{
_speechRecognitionEngine.Recognize();
}
catch (InvalidOperationException e)
{
LogLine(e.Message);
return false;
}
}}
** Send result text to an Agent in SIGverse [#b49c4788]
*** Import sigverse.dll [#afb97c89]
Follow this tutorial [[import DLL:http://www.sociointelli...
*** Send result text to SIGverse [#of8c83cf]
#highlight(c#){{
sbyte[] String2Sbytes(string text)
{
sbyte[] osb = new sbyte[text.Length];
byte[] b = Encoding.ASCII.GetBytes(text);
for (int i = 0; i < b.Length; i++)
{
osb[i] = (sbyte)b[i];
}
return osb;
}
void SendMessage2Agent(string hostname, string po...
{
MessageSender messageSender;
sbyte[] rs = String2Sbytes(message + "\0");
unsafe
{
sbyte[] _msgname = String2Sbytes("Microso...
fixed (sbyte* _mn = _msgname)
{
messageSender = new MessageSender(_mn);
fixed (sbyte* _hn = String2Sbytes(hos...
{
if (messageSender.connect(_hn, Co...
{
LogLine("Connected to [" + ho...
sbyte* a = stackalloc sbyte[r...
for (int i = 0; i < rs.Length...
{
a[i] = rs[i];
}
sbyte** _rs = &a;
sbyte[] agent = String2Sbytes...
fixed (sbyte* _agent = agent)
{
if (messageSender.sendto(...
{
LogLine("message [" +...
}
else
{
LogLine("error to sen...
}
}
}
else
{
LogLine("Can not connect to [...
}
}
}
}
}
// handle recognized event
void SpeechEngine_SpeechRecognized(object sender,...
{
...
// Send message to SIGverse's Agent here
SendMessage2Agent(_hostNameSIGverse.Text, _po...
...
}
}}
#highlight(end)
Up:[[Tutorial]] Previous:[[Samples/Communication...
#counter
Page: