Wednesday, February 21, 2007

Using the SpFileStreamClass Seek Method

After you have opened your file for reading
ISpeechFileStream sfs = new SpFileStreamClass();
sfs.Open(@"C:\dev\Speech Data\sapiWav\wavfile.wav", SpeechStreamFileMode.SSFMOpenForRead, false);

the seek method can be used to
1. return the current audio stream position in bytes
decimal position = (decimal)sfs.Seek(0, SpeechStreamSeekPositionType.SSSPTRelativeToCurrentPosition)


2. move the current audio stream position backward or forward in bytes
//I have a stereo wav file at 16000 Hz, so I use 64000
const int stereoWavBitsPerSecond = 64000;
const int monoWavBitsPerSecond = 32000;

//move forward 4 seconds for a stereo file
sfs.Seek(4 * stereoWavBitsPerSecond , SpeechStreamSeekPositionType.SSSPTRelativeToCurrentPosition)


SpeechStreamSeekPositionType values include: SSSPTRelativeToEnd, SSSPTRelativeToStart, SSSPTRelativeToCurrentPosition

No comments: