Steph
2009-01-27 05:47:01 UTC
I'm working on recognizing speech from a wav file using 5.1. Currently, my
code is not receiving events from any wav file. Is there something I'm doing
wrong?
System: XP, VS 2005, SDK 5.1,
class WavToCaption
{
private SpInProcRecoContext m_wavRecoContext;
private ISpeechRecoGrammar m_Grammar;
private SpFileStream m_infile;
public WavToCaption()
{
SpInprocRecognizer recognizer = new SpInprocRecognizer();
m_wavRecoContext =
(SpInProcRecoContext)recognizer.CreateRecoContext();
m_wavRecoContext.RetainedAudio =
SpeechRetainedAudioOptions.SRAORetainAudio;
m_infile = new SpFileStreamClass();
m_infile.Format.GetWaveFormatEx();
}
public void openWAV()
{
m_Grammar = m_wavRecoContext.CreateGrammar(0);
m_Grammar.DictationLoad("", SpeechLoadOption.SLOStatic);
//register an event handler everytime the engine recognizes
something from teh file
m_wavRecoContext.Recognition +=
new
_ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition);
//register an event handler when the engine is done reading the
file
m_wavRecoContext.EndStream +=
new
_ISpeechRecoContextEvents_EndStreamEventHandler(RecoContext_EndRecognition);
//try to open the file
try
{
m_infile.Open(@"c:\\tenyears.wav",
SpeechStreamFileMode.SSFMOpenForRead, false);
Console.Out.WriteLine("Succesfully opened file");
}
catch (Exception e)
{
Console.Out.Write("Could not find file");
return;
}
//this makes it so the engine recognizes we're reading in from a
wav, vs. a microphone
m_wavRecoContext.Recognizer.AudioInputStream = m_infile;
//starts reading the file here
m_Grammar.DictationSetState(SpeechRuleState.SGDSActive);
}
void RecoContext_Recognition(int StreamNumber, object StreamPosition,
SpeechRecognitionType RecognitionType,
ISpeechRecoResult Result)
{
//Result.PhraseInfo.GetText(0, -1, true);
Console.Out.Write("recognized something");
}
void RecoContext_EndRecognition(int StreamNumber, object
StreamPosition, bool f)
{
m_infile.Close();
m_Grammar.DictationSetState(SpeechRuleState.SGDSInactive);
}
static void Main(string[] args)
{
WavToCaption obj = new WavToCaption();
obj.openWAV();
}
}
code is not receiving events from any wav file. Is there something I'm doing
wrong?
System: XP, VS 2005, SDK 5.1,
class WavToCaption
{
private SpInProcRecoContext m_wavRecoContext;
private ISpeechRecoGrammar m_Grammar;
private SpFileStream m_infile;
public WavToCaption()
{
SpInprocRecognizer recognizer = new SpInprocRecognizer();
m_wavRecoContext =
(SpInProcRecoContext)recognizer.CreateRecoContext();
m_wavRecoContext.RetainedAudio =
SpeechRetainedAudioOptions.SRAORetainAudio;
m_infile = new SpFileStreamClass();
m_infile.Format.GetWaveFormatEx();
}
public void openWAV()
{
m_Grammar = m_wavRecoContext.CreateGrammar(0);
m_Grammar.DictationLoad("", SpeechLoadOption.SLOStatic);
//register an event handler everytime the engine recognizes
something from teh file
m_wavRecoContext.Recognition +=
new
_ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition);
//register an event handler when the engine is done reading the
file
m_wavRecoContext.EndStream +=
new
_ISpeechRecoContextEvents_EndStreamEventHandler(RecoContext_EndRecognition);
//try to open the file
try
{
m_infile.Open(@"c:\\tenyears.wav",
SpeechStreamFileMode.SSFMOpenForRead, false);
Console.Out.WriteLine("Succesfully opened file");
}
catch (Exception e)
{
Console.Out.Write("Could not find file");
return;
}
//this makes it so the engine recognizes we're reading in from a
wav, vs. a microphone
m_wavRecoContext.Recognizer.AudioInputStream = m_infile;
//starts reading the file here
m_Grammar.DictationSetState(SpeechRuleState.SGDSActive);
}
void RecoContext_Recognition(int StreamNumber, object StreamPosition,
SpeechRecognitionType RecognitionType,
ISpeechRecoResult Result)
{
//Result.PhraseInfo.GetText(0, -1, true);
Console.Out.Write("recognized something");
}
void RecoContext_EndRecognition(int StreamNumber, object
StreamPosition, bool f)
{
m_infile.Close();
m_Grammar.DictationSetState(SpeechRuleState.SGDSInactive);
}
static void Main(string[] args)
{
WavToCaption obj = new WavToCaption();
obj.openWAV();
}
}