

lucarnet
Members-
Content Count
6 -
Joined
-
Last visited
Everything posted by lucarnet
-
Prg execution time problem in Delphi11.2 IDE and command line of a DLL function
lucarnet posted a topic in Delphi IDE and APIs
Hello, In a cross-platform home automation project (Windows 11/Android 12/Debian 12), I'm having a new problem when I run this program under Delphi 11.2/FMX/Win64 which calls a "vosk_model_new" function from a "libvosk.dll" library (speech recognition library): 1) On Windows 11/Delphi 11.2FMX/Win64: when the prg is executed in the IDE in debug or release mode, the function execution time is approximately 2.5 minutes! 2) On Windows 11/Delphi 11.2FMX/Win64: when the prg is executed from the command line in a Windows window, the function execution time is acceptable (approximately 1 to 2 seconds). 3) On Delphi 11.2FMX/Android 12, the function execution time outside the IDE is acceptable (approximately 1 to 2 seconds). (Impossible to test in the IDE in DEBUG mode for Android) - On RASPI/Debian 12/Lazarus 4.0, there are no problems with the equivalent libvosk.so file. After numerous tests: - Function call in Stdcall or cdecl - With lib in static or dynamic format - Options/project/remote debugging unchecked The problem is the same, and I don't see any solution. Is it more the IDE that I should be looking for, or the Vosk DLL? Does anyone have any leads, ideally a solution? Thanks in advance, and have a nice day. The IDE log events, which list the multiple thread start/exit events (>100) during the execution of the function in the IDE. Extrait LOGS: Header unit of the DLL "Vosk_api.pas": unit VoskModelNew; interface uses SysUtils, Classes, vosk_api; type TVoskModel = class(TComponent) private { Private declarations } FModel: PVoskModel; FModelPath: String; protected { Protected declarations } public { Public declarations } //constructor Create(AOwner: TComponent); overload; override; constructor Create(AOwner: TComponent; AModelPath: String); reintroduce; destructor Destroy; override; function FindWord(AWord: String): Integer; property Model: PVoskModel read FModel; published { Published declarations } property ModelPath: String read FModelPath; end; implementation constructor TVoskModel.Create(AOwner: TComponent; AModelPath: String); var pmodelpath:pAnsichar; begin inherited Create(AOwner); FModelPath := AModelPath; pmodelpath := AnsiStrAlloc(length(Amodelpath)); StrPLCopy(pmodelpath, Amodelpath, length(Amodelpath)); try FModel := vosk_model_new(pmodelpath);//FModelPath)); finally StrDispose(pmodelpath); end; end; ... DLL function call unit: unit vosk_api; { This unit is automatically generated by Chet: https://github.com/neslib/Chet } {$MINENUMSIZE 4} interface const {$IF Defined(WIN32)} LIB_VOSK = 'libvosk.dll'; _PU = ''; {$ELSEIF Defined(WIN64)} LIB_VOSK = 'libvosk.dll'; _PU = ''; {$ELSE} {$MESSAGE Error 'Unsupported platform'} {$IFEND} type PVoskModel = Pointer; PPVoskModel = ^PVoskModel; PVoskSpkModel = Pointer; PPVoskSpkModel = ^PVoskSpkModel; PVoskRecognizer = Pointer; PPVoskRecognizer = ^PVoskRecognizer; PVoskBatchModel = Pointer; PPVoskBatchModel = ^PVoskBatchModel; PVoskBatchRecognizer = Pointer; PPVoskBatchRecognizer = ^PVoskBatchRecognizer; function vosk_model_new(const model_path: PAnsiChar): PVoskModel; cdecl; external LIB_VOSK name _PU + 'vosk_model_new'; ... DLL function call unit: logevents20250613.txt -
Prg execution time problem in Delphi11.2 IDE and command line of a DLL function
lucarnet replied to lucarnet's topic in Delphi IDE and APIs
Thanks, Kas, for your time and confirmation of the problem. 1) I don't understand "how to set the number of threads during creation." 2) The problem is identical in RELEASE mode. Changing debugger options will therefore have no effect on the problem, right? Perhaps someone from Embarcadero in this forum can help us? Thank you very much. -
Prg execution time problem in Delphi11.2 IDE and command line of a DLL function
lucarnet replied to lucarnet's topic in Delphi IDE and APIs
Your comment is very interesting; we're indeed dealing with the same type of processing. However, why does the timing issue only appear when running the code in the Delphi IDE? I'm using this same library for the speech recognition code on a Debian 12 server with Lazarus 4.0. Under Lazarus in debug or release mode, I don't have the problem; testing these same Vosk library functions under Python and C also works fine. However, I've reported the issue to the Vosk developer concerned. Perhaps you have the link to another forum where someone has encountered this same problem? Thanks in any case. -
Prg execution time problem in Delphi11.2 IDE and command line of a DLL function
lucarnet replied to lucarnet's topic in Delphi IDE and APIs
-Yes indeed, I preferred to change my topic to a more appropriate folder. -The problem only occurs when running the code in the Delphi IDE, both in debug and release mode, surprising isn’t it? -I've never used a regular profiler, but I'll look into it. thanks for your response. -
Problem execution function DLL VOSK in Delphi11.2
lucarnet posted a topic in Algorithms, Data Structures and Class Design
Hello, I am integrating a "VOSK speech recognition" into a Delphi 11.2/Fmx Windows and Android home automation application. Under w11, Execution of the library functions "libvosk.dll" is fine except for the execution time (for example, the "vosk_model_new" function). =>In IDE Delphi DEBUG or RELEASE mode, the time is 2 minutes and 30 seconds, with countless threads events (see attached log file: "Thread Start: Thread ID: 5792. Process pandroidacceslib.exe (4900) Thread Exit: Thread ID: 19852. Process pandroidacceslib.exe (4900)"). =>But in Commanline window, the time execution of the same programexe is OK(1 to 2 seconds) (execution tests in Python or C program, with the same dll, also take about 2 seconds). Does anyone have any ideas, for a solution? PS: Calling the library in cdecl or stdcall mode gives the same problem. Thanks. unit VoskModel; interface uses SysUtils, Classes, vosk_api; type TVoskModel = class(TComponent) private { Private declarations } FModel: PVoskModel; FModelPath: String; protected { Protected declarations } public { Public declarations } //constructor Create(AOwner: TComponent); overload; override; constructor Create(AOwner: TComponent; AModelPath: String); reintroduce; destructor Destroy; override; function FindWord(AWord: String): Integer; property Model: PVoskModel read FModel; published { Published declarations } property ModelPath: String read FModelPath; end; implementation //Conversion string en tbytes avec 0Terminal pour C function string_converttbytesc(vstr:string):tbytes; begin setlength(result,0); if vstr<>'' then begin result := TEncoding.UTF8.GetBytes(vstr); //Ajout 0terminale en fin de array of byte setlength(result,length(result)+1); result[length(result)-1]:=ord(#0); end; end; constructor TVoskModel.Create(AOwner: TComponent; AModelPath: String); var bytes:tbytes; begin inherited Create(AOwner); FModelPath := AModelPath; bytes:=string_converttbytesc(FModelPath); FModel := vosk_model_new(PAnsiChar(bytes));//FModelPath)); end; ... unit umaintestrecord3; interface uses {$IF CompilerVersion >= 33.0} // Delphi 10.3 Rio System.Permissions, {$ENDIF} ... type TForm1 = class(TForm) ... public { Déclarations publiques } FTVoskModel: TVoskModel; FTVoskRecognizer: TVoskRecognizer; //============================================================================ //VOSK //============================================================================ function for_voskmodel_create_parModeldir(VSampleRate:longint;var vmes:string):boolean; .... end; var Form1: TForm1; implementation {$R *.fmx} uses Math ; //========================================================================================== //VOSK //========================================================================================== function TForm1.for_voskmodel_create_parModeldir(VSampleRate:longint;var vmes:string):boolean; var vficlong:string; begin result:=false;vmes:='ModelDir:"'+FVoskModel_Dir+'":'; try //Impossibite de deployer un repertoire dans projet/deploiement: Sol:deployer un zip et dezipper vficlong:=IncludeTrailingPathDelimiter(FParamGen_DirDataVosk)+FVoskModel_Dir; if not DirectoryExists(vficlong) then showmessage('Modele Vosk "'+FVoskModel_Dir+'" introuvable') else begin String_Concatener_SLINEBREAK(vmes,'fichier Vosk "'+vficlong+'":OK'); if FTVoskModel<>nil then begin FTVoskModel.free; FTVoskModel:=nil; end; if FTVoskRecognizer<>nil then begin FTVoskRecognizer.free; FTVoskRecognizer:=nil; end; FTVoskModel:=TVoskModel.Create(Self,vficlong); if FTVoskModel.Model=nil then String_Concatener_SLINEBREAK(vmes,'FModel.Model non initialisée') else begin FTVoskRecognizer:=TVoskRecognizer.Create(Self,FTVoskModel,VSampleRate);//FHeader.SampleRate); if FTVoskRecognizer=nil then String_Concatener_SLINEBREAK(vmes,'FRecognizer=nil') else begin FTVoskRecognizer.setwords(Boolean_Boolean_convert_Int(FVoskModel_setwords)); FTVoskRecognizer.setPartialwords(Boolean_Boolean_convert_Int(FVoskModel_setPartialwords)); String_Concatener_SLINEBREAK(vmes,'for_voskmodel_create:OK(samplerate='+inttostr(VSampleRate)+')'); result:=true; end; end end; except on E:exception do vmes:=vmes+'for_voskmodel_create:'+E.message end; end; unit vosk_apiandroid; //========================================================================================== //Equivalent fichier entete "vosk_api.h" V1.0 //------------------------------------------------------------------------------------------ //Pour Windows 32 ou 64: on passe par les fonctions en direct soit en librairie statique //------------------------------------------------------------------------------------------ //Pour Android: on Charge d'abord Library dans le code soit Librairie dynamique //-Deployer arm64-v8a\libvosk.so dans repertoire library "library\lib\arm64-v8a" //-Deployer le ou les modeles Vosk: // 1)zipper le model (car deploiement de fichier uniquement): (ex:vosk-model-small-fr-0.22.zip) // Attention:le zip contient le repertoire parent (ex:"vosk-model-small-fr-0.22") // 2)Deployer le fichier.zip (ex:vosk-model-small-fr-0.22.zip) dans ".\assets\internal" // Coder Loadlibrary dans le formcreate, et Freelibrary dans le formdestroy //========================================================================================== {$MINENUMSIZE 4} interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, System.IOUtils ; const {$IF Defined(WIN32)} LIB_VOSK = 'libvosk.dll'; _PU = ''; {$ELSEIF Defined(WIN64)} LIB_VOSK = 'libvosk.dll'; _PU = ''; {$ELSEIF Defined(ANDROID)} //LIB_VOSK = 'libvosk.so'; On code "Loadlibrary" dans le formcreate _PU = ''; {$ELSE} // {$MESSAGE Error 'Unsupported platform'} {$ENDIF} type PModel = Pointer; PPModel = ^PModel; PVoskModel = Pointer; PPVoskModel = ^PVoskModel; PVoskSpkModel = Pointer; PPVoskSpkModel = ^PVoskSpkModel; PVoskRecognizer = Pointer; PPVoskRecognizer = ^PVoskRecognizer; PVoskBatchModel = Pointer; PPVoskBatchModel = ^PVoskBatchModel; PVoskBatchRecognizer = Pointer; PPVoskBatchRecognizer = ^PVoskBatchRecognizer; (** Loads model data from the file and returns the model object * * @param model_path: the path of the model on the filesystem * @returns model object or NULL if problem occured *) { function vosk_model_new(const model_path: PAnsiChar): PVoskModel; cdecl; external LIB_VOSK name _PU + 'vosk_model_new'; ... logevent_execmainvosk.txt -
Problem time execution Mode DEBUG or RUN Library Vosk
lucarnet posted a topic in Delphi IDE and APIs
Hello, I'm trying to integrate VOSK speech recognition into a Delphi 11.2/Fmx Windows and Android home automation application. Execution of the library functions "libvosk.dll" is fine except for the execution time (for example, the "vosk_model_new" function). In DEBUG mode, the time is 2 minutes and 30 seconds. In RUN mode, the time is 1 to 2 seconds (execution tests in Python or C also take about 2 seconds). Do you have any idea what I'm doing wrong (on the Delphi or Vosk library side)? PS: Calling the library in cdecl or stdcall mode gives the same problem. Thanks. Platform:Windows64b Log Mode RUN: Log mode NON DEBUG: Main Unit : unit umainvosk; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, System.IOUtils {$IFDEF MSWINDOWS},Winapi.Windows{$ENDIF} //loadlibrary ,FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Memo.Types, FMX.Edit, FMX.ScrollBox, FMX.Memo, {$IFDEF ANDROID} Androidapi.Helpers, FMX.Helpers.Android, // SharedActivityContext //Pour Lire Version Application Androidapi.JNI.JavaTypes, //FMX.Helpers.Android, Androidapi.JNI.GraphicsContentViewText, {$ENDIF ANDROID} vosk_api, voskmodelnew //voskrecognizernew ; type PVoskModel = Pointer; PPVoskModel = ^PVoskModel; const NomLib_vosk_model_new : string = 'vosk_model_new'; NomLib_vosk_model_free : string = 'vosk_model_free'; var ProcLib_vosk_model_new : function(const model_path: PAnsiChar): PVoskModel; cdecl; ProcLib_vosk_model_free : procedure(model: PVoskModel); cdecl; type TForm1 = class(TForm) btn_savetofile: TButton; Memo1: TMemo; btn_loadfromfile: TButton; btn_listefileassetsinternal: TButton; btn_listelibrary: TButton; btn_voskmodelcreate: TButton; ed_pathmodel: TEdit; btn_loadlibrary: TButton; procedure FormCreate(Sender: TObject); procedure btn_savetofileClick(Sender: TObject); procedure btn_loadfromfileClick(Sender: TObject); procedure btn_listefileassetsinternalClick(Sender: TObject); procedure btn_listelibraryClick(Sender: TObject); procedure btn_voskmodelcreateClick(Sender: TObject); procedure btn_loadlibraryClick(Sender: TObject); private { Déclarations privées } FHandle: HMODULE; FModelTest: PVoskModel; procedure for_messagedate(vmes:string); procedure for_message(vmes:string); function Librairie_charger(vnom:string;var vmes:string):boolean; public { Déclarations publiques } FTVoskModel:TVoskModel; //FPVoskModel:PVoskModel; end; {$IFDEF ANDROID} {$ENDIF} var Form1: TForm1; implementation {$R *.fmx} ... procedure TForm1.for_messagedate(vmes:string); begin memo1.lines.add(datetimetostr(now)+':'+vmes); end; procedure TForm1.for_message(vmes:string); begin if vmes<>'' then Memo1.Lines.add(vmes); end; procedure TForm1.btn_voskmodelcreateClick(Sender: TObject); var dirmodelpath, dirmodel, dirmodellong:ansistring;//important ansichar var bytes:tbytes; begin {$IFDEF ANDROID} dirmodelpath:=TPath.GetPublicPath; for_message('dirmodelpath ":'+dirpublicpath+'"'); {$ENDIF} {$IFDEF MSWINDOWS} dirmodelpath:=TPath.GetLibraryPath; for_message('GetPublicPath ":'+dirmodelpath+'"'); {$ENDIF} dirmodel:=ed_pathmodel.text; dirmodellong:=TPath.Combine(dirmodelpath,dirmodel); if not DirectoryExists(dirmodellong) then for_message('Pathmodel ":'+dirmodellong+'":INTROUVABLE') else begin for_message('Pathmodel ":'+dirmodellong+'":OK'); //Appel direct apres loadlibrary if not assigned(ProcLib_vosk_model_new) then showmessage('ProcLib_vosk_model_new non assigne') else begin bytes:=string_converttbytesc(dirmodellong); for_messagedate('Exec vosk_model_new BEGIN'); FModelTest:=ProcLib_vosk_model_new(PAnsiChar(bytes)); //<=======Exec Function for_messagedate('Exec vosk_model_new END "'); if FModelTest=nil then for_message('FModelTest.mode=nil') else begin for_message('FModelTest.model:OK') end; end; end; end; //Charger une librairie nomcourt function TForm1.Librairie_charger(vnom:string;var vmes:string):boolean; var DocDir:string; Libficlong:string; begin result:=false; DocDir := TPath.GetLibraryPath;//GetDocumentsPath; Libficlong:=TPath.Combine(TPath.GetLibraryPath,vnom);//'libvosk.so');// library if not FileExists(Libficlong) then vmes:=('Libficlong Introuvable') else begin //===================================================================== //Chargement ProcLib_vosk_model_new:=nil; ProcLib_vosk_model_free:=nil; FHandle := LoadLibrary(PCHAR(Libficlong)); if FHandle=0 then vmes:='Erreur LoadLibrary' else begin result:=true; @ProcLib_vosk_model_new :=GetProcAddress(FHandle, PWideChar(NomLib_vosk_model_new)); // using Posix function: dlsym(....), dladdr(...)... @ProcLib_vosk_model_free:=GetProcAddress(FHandle, PWideChar(NomLib_vosk_model_free)); end; end; end; ... unit exec library lib_vosk.dll: unit vosk_api; { This unit is automatically generated by Chet: https://github.com/neslib/Chet } {$MINENUMSIZE 4} interface const {$IF Defined(WIN32)} LIB_VOSK = 'libvosk.dll'; _PU = ''; {$ELSEIF Defined(WIN64)} LIB_VOSK = 'libvosk.dll'; _PU = ''; {$ELSEIF Defined(ANDROID)} LIB_VOSK = 'libvosk.so'; _PU = ''; {$ELSE} // {$MESSAGE Error 'Unsupported platform'} {$IFEND} type PVoskModel = Pointer; PPVoskModel = ^PVoskModel; PVoskSpkModel = Pointer; PPVoskSpkModel = ^PVoskSpkModel; PVoskRecognizer = Pointer; PPVoskRecognizer = ^PVoskRecognizer; PVoskBatchModel = Pointer; PPVoskBatchModel = ^PVoskBatchModel; PVoskBatchRecognizer = Pointer; PPVoskBatchRecognizer = ^PVoskBatchRecognizer; {$IFDEF ANDROID} //function vosk_model_new(const model_path: PAnsiChar): PVoskModel; stdcall external LIB_VOSK;//'libvosk.so'; function vosk_model_new(const model_path: PAnsiChar): PVoskModel; cdecl;external LIB_VOSK;//'libvosk.so'; //procedure vosk_model_free(model: PVoskModel); stdcall external LIB_VOSK;//'libvosk.so'; procedure vosk_model_free(model: PVoskModel); cdecl;external LIB_VOSK;//'libvosk.so'; //function vosk_model_find_word(model: PVoskModel; const word_: PAnsiChar): Integer; stdcall external LIB_VOSK;//'libvosk.so'; function vosk_model_find_word(model: PVoskModel; const word_: PAnsiChar): Integer; cdecl;external LIB_VOSK;//'libvosk.so'; {$ELSE} (** Loads model data from the file and returns the model object * * @param model_path: the path of the model on the filesystem * @returns model object or NULL if problem occured *) function vosk_model_new(const model_path: PAnsiChar): PVoskModel; cdecl; external LIB_VOSK name _PU + 'vosk_model_new'; (** Releases the model memory * * The model object is reference-counted so if some recognizer * depends on this model, model might still stay alive. When * last recognizer is released, model will be released too. *) procedure vosk_model_free(model: PVoskModel); cdecl; external LIB_VOSK name _PU + 'vosk_model_free'; ... joigned File:Log execution logevent_execmainvosk.txt