You are reading help file online using chmlib.com
|
ISpStream::BindToFile binds the input stream to the file that it identifies.
HRESULT BindToFile(
const WCHAR *pszFileName,
SPFILEMODE eMode,
const GUID *pguidFormatId,
const WAVEFORMATEX *pWaveFormatEx,
ULONGLONG ullEventInterest
);
Value | Description |
---|---|
S_OK | Function completed successfully. |
E_INVALIDARG | At least one of the following was encountered. pszFileName or pguidFormatId is invalid or bad; eMode exceeds SPFM_CREATE_ALWAYS; an operation could not be completed. |
E_OUTOFMEMORY | Exceeded available memory. |
STG_E_FILENOTFOUND | File pszFileName does not exist. |
SPERR_ALREADY_INITIALIZED | The object has already been initialized. |
FAILED (hr) | Appropriate error message. |
In speech recognition, ::BindToFile supports only wave audio files. It passes SAPI an audio file to pass to the engine. In text-to-speech, ::BindToFile supports both audio and text files. See ISpVoice::SpeakStream for more information.
The helper class CSpStreamFormat and the SPSTREAMFORMAT enumeration can be used to avoid the possibility of typos or mistakes when filling in the WAVEFORMATEX structure.
The following code snippet illustrates the use of ISpStream::BindToFile for creating a writable wave file
HRESULT hr = S_OK;
// create the stream object
hr = cpSpStream.CoCreateInstance(CLSID_SpStream);
// Check hr
// create a stream format helper for 22khzm 16-bit, mono wave stream
CSpStreamFormat Fmt(SPSF_22kHz16BitMono, &hr);
// Check hr
// create the new stream and its corresponding file on the hard disk
// NOTE: Specify the file format when creating the file
hr = cpSpStream->BindToFile(WAVE_FILENAME, SPFM_CREATE_ALWAYS, &Fmt.FormatId(), Fmt.WaveFormatExPtr(), NULL);
// Check hr
// write some data to the stream
hr = cpSpStream->Write(WAVE_DATA_CHUNK, SIZEOF_WAVE_DATA_CHUNK, &cbWritten);
// Check hr
The following code snippet illustrates the use of ISpStream::BindToFile for creating a read-only wave file
HRESULT hr = S_OK;
// create the stream object
hr = cpSpStream.CoCreateInstance(CLSID_SpStream);
// Check hr
// create a new stream, by opening a wave file from the hard disk
// NOTE: Since an existing file is being read, SAPI will read the wave stream format automatically
hr = cpSpStream->BindToFile(WAVE_FILENAME, SPFM_OPEN_READONLY, NULL, NULL, NULL);
// Check hr
// read some data from the stream
hr = cpSpStream->Read(&bData, SIZEOF_WAVE_DATA_CHUNK, &cbWritten);
// Check hr
You are reading help file online using chmlib.com
|