Speech recognition

Discussions related to Visual Prolog
Steve Lympany
VIP Member
Posts: 695
Joined: 31 Mar 2001 23:01

Speech recognition

Unread post by Steve Lympany » 22 Nov 2009 23:42

Hi,
I have been playing around with MS's Speech SDK SAPI 5.1, but I can't see any COM objects in my project.

I have looked at:

http://discuss.visual-prolog.com/viewtopic.php?t=7360

but haven't managed to get that far :oops:

In my VIP project, I have added "sapi.lib" (from the SDK) and "SREng.dll" as a com package. When I do that, I get a dialog called *.VPcom, but I am not sure what to do with that dialog. Otherwise, nothing seems to be loaded/included.

I have added the line (anyway, to test...):
Recognizer = spSharedRecognizer::new(),

but spSharedRecognizer can't be found.

Any ideas?

cheers
Steve

User avatar
Thomas Linder Puls
VIP Member
Posts: 2438
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 23 Nov 2009 11:38

Hi Steve. You should remove sapi.lib and SReng.dll again.

Instead you should add sapi.dll as a com package.

I believe it used to be in c:\windows\system32 on both XP and Vista, but in windows 7 it is in c:\windows\system32\speech\common. The actual place does not matter it is only used on the development machine. I.e. the resulting program will work on all machines that have a SAPI Speech Recognition engine.

I suggest that you first "play" with speech synthesis (which is far simpler to work with), just to be sure that you have hole-through.

In the attached picture I have added three components:
  • SpVoice a speech voice (the main entry for speech synthesis)
  • SpInprocRecognizer an "in process" speech recognizer (one of two main entries for speech recognition)
  • SpSharedRecognizer a "shared" speech recognizer (the second of two main entries for speech recognition)
You will only need either an "in process" or a "shared" recogonizer.
Attachments
sapiImport.png
SAPI com import
sapiImport.png (17.92 KiB) Viewed 9778 times
Regards Thomas Linder Puls
PDC

Steve Lympany
VIP Member
Posts: 695
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 23 Nov 2009 16:08

Hi Thomas,
Thanks. I didn't have a copy of SAPI.DLL on my machine (XP) at all, so I copied 2 versions (different dates) from my wife's (Vista).
So, a big step forward, but the generated code has faults - the are faults with predicates that are called with the wrong number of arguments.
Some, like:

error c229: Undeclared identifier 'unsigned64/2->'

just need core:: to supply the right class.

But:

error c229: Undeclared identifier 'unsigned16_array20/1->'

should be unsigned16_array20/20->'

and
error c229: Undeclared identifier 'comSpphrase/20->'

called with 20 args, is declared with 27 args.

error c229: Undeclared identifier 'spphraserule/1->
called with 1 arg, is declared with 8 args.

I tried with both version of SAPI.DLL, resulting with the same problems.

regards
Steve

User avatar
Thomas Linder Puls
VIP Member
Posts: 2438
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 23 Nov 2009 20:24

On XP I believe speech comes with Office rather than the operaing system itself. But I also belive there is something you can download and install from Microsoft.

Or you can install them from our WEB site http://www.pdc.dk/dk/dictus/download/sapiRedist.msi.

The problems you mention will have to be corrected manually. Fortunately for you, I have down-graded our version to Vip7.2 (there are a few extra components).

In SAPI many manual updates are necessary (also things that cannot be seen as compilation errors, but the attached version is rather good ;-)).
Attachments
sapiImport.zip
SAPI import
(346.54 KiB) Downloaded 1143 times
Regards Thomas Linder Puls
PDC

Steve Lympany
VIP Member
Posts: 695
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 24 Nov 2009 12:06

Hi Thomas,
Thank you - much appreciated.
cheers
Steve

Steve Lympany
VIP Member
Posts: 695
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 24 Nov 2009 16:47

Hi Thomas,
Sorry to be a pain, but..

I now have an executable, following Will's procedure:

http://discuss.visual-prolog.com/viewtopic.php?t=7360

but I am not sure on how to set up the callback, because of the COM changes since then (May 07).

Code: Select all

     ...              P1=ppointer(uncheckedConvert(pointer, speechEventNotifyCallback)), %also     P2=uncheckedConvert(ppointer, speechEventNotifyCallback)),              recognizerContext:setNotifyCallbackFunction(P1, 0, 0).   predicates         speechEventNotifyCallback : (unsigned WParam, integer LParam) language stdcall.
But the compiler will not accept "language stdcall":
error c370: Object predicate 'myform::speechEventNotifyCallback/2' with non-Prolog calling convention (i.e. 'language stdcall') cannot be used as a value.

If I remove the " language stdcall", the program runs, but disappears (ie crashes quietly) when I speak.

Is there a trick I'm missing?
Cheers
Steve

User avatar
Thomas Linder Puls
VIP Member
Posts: 2438
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 24 Nov 2009 21:14

Such a predicate must have "language stdcall" and it must be a class predicate. External systems does not know about "prolog" calling convention or Visual Prolog object predicate values.

I also believe that you should "uncheckedConvert" the predicate directly to the type "pPointer".

Code: Select all

    CB = uncheckedConvert(pPointer, speechEventNotifyCallback),     recognizerContext:setNotifyCallbackFunction(CB, 0, 0).   class predicates    speechEventNotifyCallback : (unsigned WParam, integer LParam) language stdcall.
If you are carefull you can pass "This" as WPARAM (uncheckedConvert to unsigned) and then invoke a predicate on it in speechEventNotifyCallback. But you should be sure that "This" is not garbage collected. The safest way to convert back from unsigned to the relevant interface is like this:

Code: Select all

Obj = convert(myInterface, uncheckedConvert(object, Wparam))
The "convert" will ensure that the object is indeed a "myInterface" object and is converted correctly.
Regards Thomas Linder Puls
PDC

Steve Lympany
VIP Member
Posts: 695
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 2 Dec 2009 11:57

Hi Thomas,
Many thanks for that. My program's doing what I want now, but COM workings seem to be a black art!
cheers
Steve

Steve Lympany
VIP Member
Posts: 695
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 12 Dec 2009 10:30

Hi Thomas,
I have a problem which is tricky to locate. Heap is sometimes not being released, but I cannot find out the circumstances. There is a trigger point of events, after which heap always goes up. There is no recovery. I can say the same phrases in different orders, and suddenly (there is no pattern), it triggers.
Here is the message window output:

TRANSMITTED>["one"]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HEAP=786432
TRANSMITTED>["two"]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HEAP=786432
TRANSMITTED>["one"]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HEAP=786432
TRANSMITTED>["one"]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HEAP=786432
TRANSMITTED>["two"]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HEAP=786432
TRANSMITTED>["one"]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HEAP=1110016
TRANSMITTED>["two"]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HEAP=1110016
TRANSMITTED>["one"]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HEAP=1716224
TRANSMITTED>["one"]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HEAP=3522560
TRANSMITTED>["two"]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HEAP=8445952
TRANSMITTED>["one"]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HEAP=13131776
TRANSMITTED>["two"]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HEAP=21245952
TRANSMITTED>["one"]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HEAP=82399232


Is there a way to force heap recovery in the callback?

Here is my code:

Code: Select all

predicates         start_sr:(string File). clauses         start_sr(File):-                 zz_spSharedRecoContext := spSharedRecoContext::new(),                 zz_iSpRecoContext_import := zz_spSharedRecoContext:get_ISpRecoContext_import(),                 zz_iSpRecoContext_import:createGrammar(0, RecognizerGrammar),                 zz_iSpRecoGrammar_import := RecognizerGrammar,                 zz_iSpRecoGrammar_import:loadCmdFromFile(File, sPLO_STATIC),                 zz_iSpRecoGrammar_import:setRuleIdState(0, sprs_active),                 zz_iSpRecoContext_import:setNotifyCallbackFunction(uncheckedConvert(ppointer, speechEventNotifyCallback), 0, 0).   constants         ulSP_GETWHOLEPHRASE = 0xFFFFFFFF.         one=1. class predicates         speechEventNotifyCallback : (unsigned WParam, integer LParam) language stdcall. clauses         speechEventNotifyCallback(_WParam, _LParam) :-         UsedHeap = convert(unsigned, memory::getUsedHeap()),                 stdIO::write("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HEAP=",UsedHeap,"\n"),                         not(isErroneous(zz_iSpRecoContext_import)),                 zz_iSpRecoContext_import:getEvents(1, EventArray, _PulFetched),                 spevent(sPEI_RECOGNITION, _,_,_,_, LParam) = EventArray,                 Result = iSpRecoResult_import::new(uncheckedConvert(iSpRecoResult_native, LParam)),                 Result:getText(ulSP_GETWHOLEPHRASE, ulSP_GETWHOLEPHRASE, 0, Text, IX),                 controller::send(Text),                 fail.                 speechEventNotifyCallback(_WParam, _LParam).
I have also tried replacing the fact variables with facts, and when I see heap getting out of control, I retractall the facts and recreate the COM, using
comMemory::freeUnusedLibraries(),

before opening the grammar again, but no heap/com memory is released.


regards
Steve

User avatar
Thomas Linder Puls
VIP Member
Posts: 2438
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 14 Dec 2009 16:07

Hi, Steve.

It is very difficult to solve such problem (and even more when only having access to a fragment of the program).

I can however adwise that you use the memory profiler on the project. It will give you an image like the one in this mail: Speech recognition using COM and Windows Speech API. It may be a good idea to become acquainted with it in a simpler project first.
Regards Thomas Linder Puls
PDC

viktorz
Posts: 1
Joined: 29 Mar 2012 9:31

Unread post by viktorz » 29 Mar 2012 9:32

Until is binary processor speech recognition will be buggy ))
i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15
i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15
i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15
i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15
i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15
i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15i15
i15i15i15i15i15i15i15i15i15i15i15i15i15
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
Last edited by viktorz on 21 Sep 2018 11:11, edited 4 times in total.

Steve Lympany
VIP Member
Posts: 695
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 29 Mar 2012 10:02

Hi,
Well the problem was mine, and was resolved 3 years ago. Runs fine, stable, and not buggy at all (for me at least)
cheers
Steve

Post Reply