-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Microsoft.ML.OnnxRuntimeGenAI | ||
{ | ||
public class Audios : IDisposable | ||
{ | ||
private IntPtr _audiosHandle; | ||
private bool _disposed = false; | ||
|
||
private Audios(IntPtr audiosHandle) | ||
{ | ||
_audiosHandle = audiosHandle; | ||
} | ||
|
||
internal IntPtr Handle { get { return _audiosHandle; } } | ||
|
||
public static Audios Load(string[] audioPaths) | ||
{ | ||
Result.VerifySuccess(NativeMethods.OgaCreateStringArray(out IntPtr stringArray)); | ||
foreach (string audioPath in audioPaths) | ||
{ | ||
Result.VerifySuccess(NativeMethods.OgaStringArrayAddString(stringArray, StringUtils.ToUtf8(audioPath))); | ||
} | ||
Result.VerifySuccess(NativeMethods.OgaLoadAudios(stringArray, out IntPtr audiosHandle)); | ||
NativeMethods.OgaDestroyStringArray(stringArray); | ||
return new Audios(audiosHandle); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (_disposed) | ||
{ | ||
return; | ||
} | ||
NativeMethods.OgaDestroyAudios(_audiosHandle); | ||
_audiosHandle = IntPtr.Zero; | ||
_disposed = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters