You are here:

C++/SAPI LoadCmdFromFile question

Advertisement


Question
I'm sorry, I neglected to mention that I'm developing on Windows XP to be run on XP, so it isn't a problem with it not supporting unicode, as far as I know.  My project is very simple so far.  It just creates a window and attempts to initialize speech recognition, but it always gets hung on loading the grammar file.  If you would like, or rather, wouldn't mind, I could post the project or email it to you so you can see exactly what I have.  
Again, I really apreciate you taking your time for this.

Michael Lane


-------------------------
Followup To
Question -
Hi there, I'm not sure if you have any experience with this or not, but I figure it's worth a shot. I'm using VS.Net, writing in C++. I am writing a program to control a music playlist by voice commands and I need to load the grammar from an external file that will periodically be updated. The SDK shows that LoadCmdFromFile is what I need, so I call the command and I always receive E_INVALIDARG error when the function returns. According to the documentation, that means "...FileName is invalid or bad. Alternatively, Options is neither SPLO_STATIC nor SPLO_DYNAMIC."

I call it like so:
g_Grammar->LoadCmdFromFile(L"mygrammar.xml",SPLO_DYNAMIC);

I have mygrammar.xml in the project directory, and the debug directory, so I know it is there, and I've also tried sending the function the entire path, but it always returns the same.

Do you have any ideas on what might be causing this?

Notes:
ISpRecoGrammar::LoadCmdFromFile
ISpRecoGrammar::LoadCmdFromFile loads a SAPI 5 command and control grammar from a file. The file can either be a compiled or uncompiled grammar file. To modify the rules of the grammar after it has been loaded, specify SPLO_DYNAMIC for the Options parameter, otherwise specify the SPLO_STATIC flag.

HRESULT LoadCmdFromFile(
   const WCHAR    *pszFileName,
   SPLOADOPTIONS   Options
);

Parameters
pszFileName
[in, string] The name of the file containing the command and control grammar. SAPI 5 support loading of compiled and static grammars using URL.
Options
[in] Flag of type SPLOADOPTIONS indicating whether the grammar will be modified dynamically.
Return values
Value Description
S_OK Function completed successfully.
E_INVALIDARG pszFileName is invalid or bad. Alternatively, Options is neither SPLO_STATIC nor SPLO_DYNAMIC.
FAILED(hr) Appropriate error message.


mygrammar.xml:
<GRAMMAR LANGID="409">
   <DEFINE>
      <ID NAME="VID_Command" VAL="1"/>
   </DEFINE>
   <RULE ID="VID_Command" TOPLEVEL="ACTIVE">
<L>
<P>Exit</P>
<P>Close</P>
</L>
   </RULE>
</GRAMMAR>


Well, I certainly appreciate your time in looking over this.

Michael Lane

Answer -
Michael, Thank you for your question.

This looks like a very interesting application, and one that might be of interest to blind and visually impaired computer users (this is an area of interest for me).

My guess is that the problem is in the statement

g_Grammar->LoadCmdFromFile(L"mygrammar.xml",SPLO_DYNAMIC);

You are using a wide character string literal. But perhaps you are running under Windows 98 or some such, where the file system does not use Unicode.

Let me know if this is not the problem, and I'll think about it some more.

David Spector


Answer
Michael, Actually I am interested in your project, as I have used some of SAPI in the past.

It would be great if you could make all the project files available to me. Then I could create a local Visual C++ project and see if I can give you some direct help.

Note that I use Windows 98, but that should not be an obstacle.

You can send me your files (perhaps as a Zip file attachment) by using the temporary email address formed by concatenating "ma" with "x@springtimesoftware.com". Please do not send any large files, as I have a slow dialup connection.

Bear in mind that all AllExperts messages are public.

David

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


David Spector

Expertise

Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.

Experience

I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Publications
Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

Education/Credentials
ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 About.com. All rights reserved.