Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Whisper.net/WhisperFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ private WhisperFactory(IWhisperProcessorModelLoader loader, bool delayInit)

var systemInfoPtr = libraryLoaded.Value.NativeWhisper!.WhisperPrintSystemInfo();
var systemInfoStr = Marshal.PtrToStringAnsi(systemInfoPtr);
Marshal.FreeHGlobal(systemInfoPtr);
// The pointer returned by WhisperPrintSystemInfo points to a static
// buffer owned by the native library. Do not free it here.
return systemInfoStr;
}

Expand Down
34 changes: 22 additions & 12 deletions Whisper.net/WhisperProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,28 @@ private unsafe Task ProcessInternalAsync(ReadOnlyMemory<float> samples, Cancella
private IntPtr GetWhisperState()
{
var state = nativeWhisper.Whisper_Init_State(currentWhisperContext);
if (RuntimeOptions.LoadedLibrary == RuntimeLibrary.OpenVino)
{
var modelPath = Marshal.StringToHGlobalAnsi(options.OpenVinoModelPath);
var device = Marshal.StringToHGlobalAnsi(options.OpenVinoDevice);
var cachePath = Marshal.StringToHGlobalAnsi(options.OpenVinoCacheDir);
nativeWhisper.Whisper_Ctx_Init_Openvino_Encoder_With_State(
options.ContextHandle,
state,
modelPath,
device,
cachePath);
}
if (RuntimeOptions.LoadedLibrary == RuntimeLibrary.OpenVino)
{
var modelPath = Marshal.StringToHGlobalAnsi(options.OpenVinoModelPath);
var device = Marshal.StringToHGlobalAnsi(options.OpenVinoDevice);
var cachePath = Marshal.StringToHGlobalAnsi(options.OpenVinoCacheDir);

try
{
nativeWhisper.Whisper_Ctx_Init_Openvino_Encoder_With_State(
options.ContextHandle,
state,
modelPath,
device,
cachePath);
}
finally
{
Marshal.FreeHGlobal(modelPath);
Marshal.FreeHGlobal(device);
Marshal.FreeHGlobal(cachePath);
}
}
return state;
}

Expand Down
Loading