lucarnet 0 Posted 11 hours ago 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 Share this post Link to post
Der schöne Günther 336 Posted 10 hours ago This is the same question as last time, right? Problem time execution Mode DEBUG or RUN Library Vosk - Delphi IDE and APIs - Delphi-PRAXiS [en] There is no functional problem, it's just that the performance is not acceptable when being debugged, right? Have you tried using a regular profiler? Share this post Link to post
Kas Ob. 138 Posted 10 hours ago 28 minutes ago, lucarnet said: Is it more the IDE that I should be looking for, or the Vosk DLL? Does anyone have any leads, ideally a solution? Don't know what is Vosk is and will not search the internet, one thing i can see is very wrong in your attached log file The amount of threads started and exited is huge and wrong, so 1) Either there is some setting your are missing to let such library utilize threading pool right, or you are calling the wrong model. 2) You are loading and unloading the library or part of it so may times ! Check these, because i don't believe a normal and tested library should use so much thread in such manner, that makes no sense at all. Share this post Link to post
Kas Ob. 138 Posted 10 hours ago I just remembered seeing a code or something were the the programmer tried to decode audio captured into image, so the audio is PCM and at minimum (standard minimum) and will be 8000 sample per second, and he was trying to spawn a thread for each sample to perform Fourier transformation on each and every sample, so his idea was to spawn 8000 thread per second at least, i think you are making a mistake close or similar to this, so in case these threads are yours then rethink again and find a working demo or the from documentation on how to feed the data the right way. Share this post Link to post
lucarnet 0 Posted 4 hours ago Quote This is the same question as last time, right? Problem time execution Mode DEBUG or RUN Library Vosk - Delphi IDE and APIs - Delphi-PRAXiS [en] There is no functional problem, it's just that the performance is not acceptable when being debugged, right? Have you tried using a regular profiler? -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. Share this post Link to post
lucarnet 0 Posted 4 hours ago 5 hours ago, Kas Ob. said: I just remembered seeing a code or something were the the programmer tried to decode audio captured into image, so the audio is PCM and at minimum (standard minimum) and will be 8000 sample per second, and he was trying to spawn a thread for each sample to perform Fourier transformation on each and every sample, so his idea was to spawn 8000 thread per second at least, i think you are making a mistake close or similar to this, so in case these threads are yours then rethink again and find a working demo or the from documentation on how to feed the data the right way. 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. Share this post Link to post
Lajos Juhász 320 Posted 1 hour ago It could be that when the library detects the debugger it slows down. You can try using Lazarus at Windows to see if it behaves the same. Share this post Link to post