Recent

Author Topic: Any successful experience with SpeechToText API on Windows?  (Read 20100 times)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Any successful experience with SpeechToText API on Windows?
« Reply #15 on: July 03, 2015, 05:22:49 pm »
Maybe they are already implemented:

Code: [Select]
procedure InterfaceConnect(const Source: IUnknown; const IID: TIID; const Sink: IUnknown; var Connection: DWORD);
     var
       CPC: IConnectionPointContainer;
       CP: IConnectionPoint;
       i: hresult;
     begin
       Connection := 0;
       if Succeeded(Source.QueryInterface(IConnectionPointContainer, CPC)) then
         if Succeeded(CPC.FindConnectionPoint(IID, CP)) then
           i:=CP.Advise(Sink, Connection);
     end;


   procedure InterfaceDisconnect(const Source: IUnknown; const IID: TIID; var Connection: DWORD);
     var
       CPC: IConnectionPointContainer;
       CP: IConnectionPoint;
       i: hresult;
     begin
       if Connection <> 0 then
         if Succeeded(Source.QueryInterface(IConnectionPointContainer, CPC)) then
           if Succeeded(CPC.FindConnectionPoint(IID, CP)) then
           begin
             i:=CP.Unadvise(Connection);
             if Succeeded(i) then Connection := 0;
           end;
     end;   

balazsszekely

  • Guest
Re: Any successful experience with SpeechToText API on Windows?
« Reply #16 on: July 03, 2015, 05:33:11 pm »
Yes they did! The last time, somehow I was looking at fpc 2.6.4 source.
Great! Then your pach should work.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Any successful experience with SpeechToText API on Windows?
« Reply #17 on: July 03, 2015, 06:08:30 pm »
No, "Tools > Import Type Library..." is for importing definitions of a dll, etc. and creating a TLB-file (just like you can in Delphi).

It will create a TLB-file which should be compatible with FPC/Lazarus without any modification needed.

There is no need to use a TLB generated by Delphi. You can look in the headers of that file to see from which dll it is generated and you can generate your own TLB with the tool from Lazarus.

Where it that?

Perhaps you refer to this:

http://forum.lazarus.freepascal.org/index.php?topic=5471.0
« Last Edit: July 03, 2015, 06:14:22 pm by typo »

rvk

  • Hero Member
  • *****
  • Posts: 6656
Re: Any successful experience with SpeechToText API on Windows?
« Reply #18 on: July 03, 2015, 06:18:34 pm »
No, "Tools > Import Type Library..." is for importing definitions of a dll, etc. and creating a TLB-file (just like you can in Delphi).

It will create a TLB-file which should be compatible with FPC/Lazarus without any modification needed.

There is no need to use a TLB generated by Delphi. You can look in the headers of that file to see from which dll it is generated and you can generate your own TLB with the tool from Lazarus.

Where it that?
If you look in your own SpeechLib_TLB you'll see this:
Quote
// PASTLWTR : 1.2
// File generated on 07.01.2007 12:06:43 from Type Library described below.

// ************************************************************************  //
// Type Lib: C:\Program Files\Common Files\Microsoft Shared\Speech\sapi.dll (1)
// LIBID: {C866CA3A-32F7-11D2-9602-00C04F8EE628}
// LCID: 0
// Helpfile:
// HelpString: Microsoft Speech Object Library
// DepndLst:
//   (1) v2.0 stdole, (C:\WINDOWS\system32\stdole2.tlb)
So it's generated by someone who had a sapi.dll in their "Common Files\Microsoft Shared\Speech" and an old Windows-version !!

I can't find it there on my machine but if I look for sapi.dll I find a couple:
C:\Windows\SysWOW64\Speech\Common\sapi.dll
C:\Windows\System32\Speech\Common\sapi.dll

My guess is you need the 32bit version so this one:
C:\Windows\SysWOW64\Speech\Common\sapi.dll

So with the , "Tools > Import Type Library..." you can create your very own TLB with Lazarus itself.

The implementation is slightly different than that of Delphi's.
(i.e. you need to use TAxcSpSharedRecoContext.OleServer.EventInterests instead of TSpSharedRecoContext1.EventInterests, I think)

« Last Edit: July 03, 2015, 06:21:11 pm by rvk »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Any successful experience with SpeechToText API on Windows?
« Reply #19 on: July 03, 2015, 06:20:37 pm »
Was it also automatically generated like Delphi does, but for Lazarus?

Please post the file.

rvk

  • Hero Member
  • *****
  • Posts: 6656
Re: Any successful experience with SpeechToText API on Windows?
« Reply #20 on: July 03, 2015, 06:22:50 pm »
Was it also automatically generated as Delphi does, but for Lazarus?

Please post the file.
Ok, It was already included in that listening.zip I posted earlier.

But here it is again :)

(But like I showed in my last post, it's fairly easy to generate it yourself)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Any successful experience with SpeechToText API on Windows?
« Reply #21 on: July 03, 2015, 06:23:58 pm »
Thanks.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Any successful experience with SpeechToText API on Windows?
« Reply #22 on: July 03, 2015, 06:36:37 pm »
I have just installed ActiveX package and Import Type Library menu item appears in the menu now. Thanks.

Now I could generate my own file.
« Last Edit: July 03, 2015, 06:43:10 pm by typo »

rvk

  • Hero Member
  • *****
  • Posts: 6656
Re: Any successful experience with SpeechToText API on Windows?
« Reply #23 on: July 03, 2015, 06:43:44 pm »
I have just installed ActiveX package and Import Type Library menu item appears in the menu now. Thanks.
Argh... Yeah... I didn't realize that menu-option was dependent on the ActiveX package being loaded  %)

Anyway... I can successfully create the speech object and the Speech-recognition app opens up (without problems).

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  SpSharedRecoContext1: TAxcSpSharedRecoContext;
begin
  SpSharedRecoContext1 := TAxcSpSharedRecoContext.Create(self);
  SpSharedRecoContext1.OleServer.EventInterests := SREAllEvents;
  SpSharedRecoContext1.OnHypothesis := @SpSharedRecoContext1Hypothesis;
  SpSharedRecoContext1.OnRecognition := @SpSharedRecoContext1Recognition;
  fMyGrammar := SpSharedRecoContext1.OleServer.CreateGrammar(0);
  fMyGrammar.DictationSetState(SGDSActive);
end;

I'm not sure how to implement that fMyGrammar. (SpSharedRecoContext1.CreateGrammar creates a ISpeechRecoGrammar)

But I'm not getting the events in my procedures.


Edit: Correction... IT'S WORKING  :D :D :D :D
« Last Edit: July 03, 2015, 06:47:58 pm by rvk »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Any successful experience with SpeechToText API on Windows?
« Reply #24 on: July 03, 2015, 07:03:17 pm »
For me Lazarus can not find TAxcSpSharedRecoContext class.

I got my DLL from System32\Speech\Common.

Perhaps I need to wait for FPC to fix it.

When I use your file, I have a runtime error on CoSpSharedRecoContext.Create method.
« Last Edit: July 03, 2015, 07:12:44 pm by typo »

rvk

  • Hero Member
  • *****
  • Posts: 6656
Re: Any successful experience with SpeechToText API on Windows?
« Reply #25 on: July 03, 2015, 07:06:41 pm »
For me Lazarus can not find TAxcSpSharedRecoContext class.
Did you check the "Create visual component" when importing the type library?
(only then will the TAxcSpSharedRecoContext class be created)

See attached image (with the little arrow).

(also attached my very simple working example)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Any successful experience with SpeechToText API on Windows?
« Reply #26 on: July 03, 2015, 07:20:03 pm »
You are right, I fixed it, but my error persists. It is an EOleSysError on CoSpSharedRecoContext.Create method.
« Last Edit: July 03, 2015, 07:22:12 pm by typo »

rvk

  • Hero Member
  • *****
  • Posts: 6656
Re: Any successful experience with SpeechToText API on Windows?
« Reply #27 on: July 03, 2015, 07:21:58 pm »
You are right, I fixed it, but my error persists. It is an EOleSysError.
Mmm, are you seeing the same error with my example (from my last post)?

I got my DLL from System32\Speech\Common.
Are you on a 32bit windows version?
The 32bit version of the dll is on SysWOW64 on a 64bit machine.

Are you using FPC/Lazarus trunk ?
« Last Edit: July 03, 2015, 07:24:08 pm by rvk »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Any successful experience with SpeechToText API on Windows?
« Reply #28 on: July 03, 2015, 07:24:34 pm »
Yes, I have it running your example too.

Even if I replace your speechlib_5_4_tlb by the mine in your example, the error persists.
« Last Edit: July 03, 2015, 07:32:50 pm by typo »

rvk

  • Hero Member
  • *****
  • Posts: 6656
Re: Any successful experience with SpeechToText API on Windows?
« Reply #29 on: July 03, 2015, 07:26:37 pm »
Yes, I have it running your example too.
It even runs in Laz1.4 without your patch from earlier  :D

 

TinyPortal © 2005-2018