FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log inLog in 


Speech recognition

Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog
View previous topic :: View next topic  
Author Message
Steve Lympany



Horsham, England
Joined: 31 Mar 2001
Posts: 1152

PostPosted: 22 Nov 2009 23:42    Post subject: Speech recognition Reply with quote

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 Embarassed

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
Back to top
View user's profile Send private message Visit poster's website
Thomas Linder Puls



Copenhagen, Denmark
Joined: 28 Feb 2000
Posts: 3104

PostPosted: 23 Nov 2009 11:38    Post subject: Reply with quote

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.



sapiImport.png
 Description:
SAPI com import
 Filesize:  17.92 KB
 Viewed:  7483 Time(s)

sapiImport.png



_________________
Regards Thomas Linder Puls
Prolog Development Center
Back to top
View user's profile Send private message
Steve Lympany



Horsham, England
Joined: 31 Mar 2001
Posts: 1152

PostPosted: 23 Nov 2009 16:08    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Thomas Linder Puls



Copenhagen, Denmark
Joined: 28 Feb 2000
Posts: 3104

PostPosted: 23 Nov 2009 20:24    Post subject: Reply with quote

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 Wink).



sapiImport.zip
 Description:
SAPI import

Download
 Filename:  sapiImport.zip
 Filesize:  346.54 KB
 Downloaded:  1055 Time(s)


_________________
Regards Thomas Linder Puls
Prolog Development Center
Back to top
View user's profile Send private message
Steve Lympany



Horsham, England
Joined: 31 Mar 2001
Posts: 1152

PostPosted: 24 Nov 2009 12:06    Post subject: Reply with quote

Hi Thomas,
Thank you - much appreciated.
cheers
Steve
Back to top
View user's profile Send private message Visit poster's website
Steve Lympany



Horsham, England
Joined: 31 Mar 2001
Posts: 1152

PostPosted: 24 Nov 2009 16:47    Post subject: Reply with quote

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).


     ...
             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
Back to top
View user's profile Send private message Visit poster's website
Thomas Linder Puls



Copenhagen, Denmark
Joined: 28 Feb 2000
Posts: 3104

PostPosted: 24 Nov 2009 21:14    Post subject: Reply with quote

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".

    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:

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
Prolog Development Center
Back to top
View user's profile Send private message
Steve Lympany



Horsham, England
Joined: 31 Mar 2001
Posts: 1152

PostPosted: 2 Dec 2009 11:57    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Steve Lympany



Horsham, England
Joined: 31 Mar 2001
Posts: 1152

PostPosted: 12 Dec 2009 10:30    Post subject: Reply with quote

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:


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
Back to top
View user's profile Send private message Visit poster's website
Thomas Linder Puls



Copenhagen, Denmark
Joined: 28 Feb 2000
Posts: 3104

PostPosted: 14 Dec 2009 16:07    Post subject: Reply with quote

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
Prolog Development Center
Back to top
View user's profile Send private message
viktorz




Joined: 29 Mar 2012
Posts: 1

PostPosted: 29 Mar 2012 9:32    Post subject: Reply with quote

Until is binary processor speech recognition will be buggy ))
астигматизм96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o
96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o
96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o
96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o
96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o
96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o
96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o
96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o96o


Last edited by viktorz on 9 Nov 2015 13:38; edited 2 times in total
Back to top
View user's profile Send private message
Steve Lympany



Horsham, England
Joined: 31 Mar 2001
Posts: 1152

PostPosted: 29 Mar 2012 10:02    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum