Discussion:
Wav To Text Conversion
(too old to reply)
Steph
2009-01-27 05:47:01 UTC
Permalink
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();
}
}
Marty Markoe - eMicrophones, Inc.
2009-01-27 12:13:01 UTC
Permalink
Post by Steph
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,
We know you can do this in Vista's Windows Speech Recognition because the
WSRToolkit has Transcription from a .wav file built in. See the WSRToolkit at:
http://www.mymssspeech.com/microphones/prod_details.asp?prodID=228

Marty Markoe, eMicrophones, Inc.
naresh
2009-01-28 14:20:03 UTC
Permalink
replace the following code

m_Grammar = m_wavRecoContext.CreateGrammar(0);
m_Grammar.DictationLoad("", SpeechLoadOption.SLOStatic);

with

private DictationGrammar dictationGrammar = null;


//Creating an instance of the grammer object.
dictationGrammar = new DictationGrammar();
dictationGrammar.Name = "dictationtest1";
dictationGrammar.Enabled = true;

//Load the grammar into the speech engine

MySpeechRecEngineSystemDotSpeech.LoadGrammar(dictationGrammar);

hope this helps you
Post by Steph
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
{
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();
}
}
Hari
2009-01-28 20:26:00 UTC
Permalink
Hi Steph,

I suppose that you need to assign the audio stream to the recocontext's
recognizer. Please include the following line in the OpenWAV method next to
the opening of file stream as follows and let me know:
try
{
m_infile.Open(@"c:\\tenyears.wav",
SpeechStreamFileMode.SSFMOpenForRead, false);
if(m_infile!=null)
{
m_wavRecoContext.Recognizer.AudioInputStream=m_infile;
Console.Out.WriteLine("Succesfully opened file");
}
}
--
Thanks,
Hari
Post by Steph
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
{
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();
}
}
Hari
2009-01-28 20:35:00 UTC
Permalink
I think you need to assign the audio stream to the recognizer -
m_wavRecoContext.Recognizer.AudioInputStream=m_infile - inside your OpenWAV
method.

Please have a look at http://gotspeech.net/forums/thread/6835.aspx.
--
Thanks,
Hari
Post by Steph
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
{
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();
}
}
Steph
2009-02-06 00:29:01 UTC
Permalink
Thanks for everyone's help :-)

I ended up scrapping my code that night and making it work with
SpeechRecognitionEngine. I lost where this thread and just now found it.

Thanks!
Post by Hari
I think you need to assign the audio stream to the recognizer -
m_wavRecoContext.Recognizer.AudioInputStream=m_infile - inside your OpenWAV
method.
Please have a look at http://gotspeech.net/forums/thread/6835.aspx.
--
Thanks,
Hari
Post by Steph
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
{
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();
}
}
Loading...