Refactor C API to prefix each API with SherpaOnnx. (#1171)
This commit is contained in:
@@ -9,7 +9,6 @@ environment:
|
||||
sdk: ^3.4.0
|
||||
|
||||
dependencies:
|
||||
# sherpa_onnx: ^1.10.18
|
||||
sherpa_onnx:
|
||||
path: ../../flutter/sherpa_onnx
|
||||
path: ^1.9.0
|
||||
|
||||
@@ -17,7 +17,7 @@ topics:
|
||||
- voice-activity-detection
|
||||
|
||||
# remember to change the version in ../sherpa_onnx_macos/macos/sherpa_onnx.podspec
|
||||
version: 1.10.18
|
||||
version: 1.10.19
|
||||
|
||||
homepage: https://github.com/k2-fsa/sherpa-onnx
|
||||
|
||||
|
||||
@@ -13,20 +13,20 @@ namespace SherpaOnnx
|
||||
{
|
||||
public KeywordSpotter(KeywordSpotterConfig config)
|
||||
{
|
||||
IntPtr h = CreateKeywordSpotter(ref config);
|
||||
IntPtr h = SherpaOnnxCreateKeywordSpotter(ref config);
|
||||
_handle = new HandleRef(this, h);
|
||||
}
|
||||
|
||||
public OnlineStream CreateStream()
|
||||
{
|
||||
IntPtr p = CreateKeywordStream(_handle.Handle);
|
||||
IntPtr p = SherpaOnnxCreateKeywordStream(_handle.Handle);
|
||||
return new OnlineStream(p);
|
||||
}
|
||||
|
||||
public OnlineStream CreateStream(string keywords)
|
||||
{
|
||||
byte[] utf8Bytes = Encoding.UTF8.GetBytes(keywords);
|
||||
IntPtr p = CreateKeywordStreamWithKeywords(_handle.Handle, utf8Bytes);
|
||||
IntPtr p = SherpaOnnxCreateKeywordStreamWithKeywords(_handle.Handle, utf8Bytes);
|
||||
return new OnlineStream(p);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace SherpaOnnx
|
||||
|
||||
private void Cleanup()
|
||||
{
|
||||
DestroyKeywordSpotter(_handle.Handle);
|
||||
SherpaOnnxDestroyKeywordSpotter(_handle.Handle);
|
||||
|
||||
// Don't permit the handle to be used again.
|
||||
_handle = new HandleRef(this, IntPtr.Zero);
|
||||
@@ -90,30 +90,30 @@ namespace SherpaOnnx
|
||||
private HandleRef _handle;
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern IntPtr CreateKeywordSpotter(ref KeywordSpotterConfig config);
|
||||
private static extern IntPtr SherpaOnnxCreateKeywordSpotter(ref KeywordSpotterConfig config);
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern void DestroyKeywordSpotter(IntPtr handle);
|
||||
private static extern void SherpaOnnxDestroyKeywordSpotter(IntPtr handle);
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern IntPtr CreateKeywordStream(IntPtr handle);
|
||||
private static extern IntPtr SherpaOnnxCreateKeywordStream(IntPtr handle);
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern IntPtr CreateKeywordStreamWithKeywords(IntPtr handle, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I1)] byte[] utf8Keywords);
|
||||
private static extern IntPtr SherpaOnnxCreateKeywordStreamWithKeywords(IntPtr handle, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I1)] byte[] utf8Keywords);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "IsKeywordStreamReady")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxIsKeywordStreamReady")]
|
||||
private static extern int IsReady(IntPtr handle, IntPtr stream);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "DecodeKeywordStream")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxDecodeKeywordStream")]
|
||||
private static extern void Decode(IntPtr handle, IntPtr stream);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "DecodeMultipleKeywordStreams")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxDecodeMultipleKeywordStreams")]
|
||||
private static extern void Decode(IntPtr handle, IntPtr[] streams, int n);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "GetKeywordResult")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxGetKeywordResult")]
|
||||
private static extern IntPtr GetResult(IntPtr handle, IntPtr stream);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "DestroyKeywordResult")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxDestroyKeywordResult")]
|
||||
private static extern void DestroyResult(IntPtr result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ namespace SherpaOnnx
|
||||
{
|
||||
public OfflineRecognizer(OfflineRecognizerConfig config)
|
||||
{
|
||||
IntPtr h = CreateOfflineRecognizer(ref config);
|
||||
IntPtr h = SherpaOnnxCreateOfflineRecognizer(ref config);
|
||||
_handle = new HandleRef(this, h);
|
||||
}
|
||||
|
||||
public OfflineStream CreateStream()
|
||||
{
|
||||
IntPtr p = CreateOfflineStream(_handle.Handle);
|
||||
IntPtr p = SherpaOnnxCreateOfflineStream(_handle.Handle);
|
||||
return new OfflineStream(p);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace SherpaOnnx
|
||||
|
||||
private void Cleanup()
|
||||
{
|
||||
DestroyOfflineRecognizer(_handle.Handle);
|
||||
SherpaOnnxDestroyOfflineRecognizer(_handle.Handle);
|
||||
|
||||
// Don't permit the handle to be used again.
|
||||
_handle = new HandleRef(this, IntPtr.Zero);
|
||||
@@ -63,18 +63,18 @@ namespace SherpaOnnx
|
||||
private HandleRef _handle;
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern IntPtr CreateOfflineRecognizer(ref OfflineRecognizerConfig config);
|
||||
private static extern IntPtr SherpaOnnxCreateOfflineRecognizer(ref OfflineRecognizerConfig config);
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern void DestroyOfflineRecognizer(IntPtr handle);
|
||||
private static extern void SherpaOnnxDestroyOfflineRecognizer(IntPtr handle);
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern IntPtr CreateOfflineStream(IntPtr handle);
|
||||
private static extern IntPtr SherpaOnnxCreateOfflineStream(IntPtr handle);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "DecodeOfflineStream")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxDecodeOfflineStream")]
|
||||
private static extern void Decode(IntPtr handle, IntPtr stream);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "DecodeMultipleOfflineStreams")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxDecodeMultipleOfflineStreams")]
|
||||
private static extern void Decode(IntPtr handle, IntPtr[] streams, int n);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace SherpaOnnx
|
||||
|
||||
private void Cleanup()
|
||||
{
|
||||
DestroyOfflineStream(Handle);
|
||||
SherpaOnnxDestroyOfflineStream(Handle);
|
||||
|
||||
// Don't permit the handle to be used again.
|
||||
_handle = new HandleRef(this, IntPtr.Zero);
|
||||
@@ -54,15 +54,15 @@ namespace SherpaOnnx
|
||||
public IntPtr Handle => _handle.Handle;
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern void DestroyOfflineStream(IntPtr handle);
|
||||
private static extern void SherpaOnnxDestroyOfflineStream(IntPtr handle);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "AcceptWaveformOffline")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxAcceptWaveformOffline")]
|
||||
private static extern void AcceptWaveform(IntPtr handle, int sampleRate, float[] samples, int n);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "GetOfflineStreamResult")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxGetOfflineStreamResult")]
|
||||
private static extern IntPtr GetResult(IntPtr handle);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "DestroyOfflineRecognizerResult")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxDestroyOfflineRecognizerResult")]
|
||||
private static extern void DestroyResult(IntPtr handle);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,13 +14,13 @@ namespace SherpaOnnx
|
||||
{
|
||||
public OnlineRecognizer(OnlineRecognizerConfig config)
|
||||
{
|
||||
IntPtr h = CreateOnlineRecognizer(ref config);
|
||||
IntPtr h = SherpaOnnxCreateOnlineRecognizer(ref config);
|
||||
_handle = new HandleRef(this, h);
|
||||
}
|
||||
|
||||
public OnlineStream CreateStream()
|
||||
{
|
||||
IntPtr p = CreateOnlineStream(_handle.Handle);
|
||||
IntPtr p = SherpaOnnxCreateOnlineStream(_handle.Handle);
|
||||
return new OnlineStream(p);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace SherpaOnnx
|
||||
/// true.
|
||||
public bool IsEndpoint(OnlineStream stream)
|
||||
{
|
||||
return IsEndpoint(_handle.Handle, stream.Handle) != 0;
|
||||
return SherpaOnnxOnlineStreamIsEndpoint(_handle.Handle, stream.Handle) != 0;
|
||||
}
|
||||
|
||||
/// You have to ensure that IsReady(stream) returns true before
|
||||
@@ -71,7 +71,7 @@ namespace SherpaOnnx
|
||||
/// When this method returns, IsEndpoint(stream) will return false.
|
||||
public void Reset(OnlineStream stream)
|
||||
{
|
||||
Reset(_handle.Handle, stream.Handle);
|
||||
SherpaOnnxOnlineStreamReset(_handle.Handle, stream.Handle);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -89,7 +89,7 @@ namespace SherpaOnnx
|
||||
|
||||
private void Cleanup()
|
||||
{
|
||||
DestroyOnlineRecognizer(_handle.Handle);
|
||||
SherpaOnnxDestroyOnlineRecognizer(_handle.Handle);
|
||||
|
||||
// Don't permit the handle to be used again.
|
||||
_handle = new HandleRef(this, IntPtr.Zero);
|
||||
@@ -98,33 +98,33 @@ namespace SherpaOnnx
|
||||
private HandleRef _handle;
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern IntPtr CreateOnlineRecognizer(ref OnlineRecognizerConfig config);
|
||||
private static extern IntPtr SherpaOnnxCreateOnlineRecognizer(ref OnlineRecognizerConfig config);
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern void DestroyOnlineRecognizer(IntPtr handle);
|
||||
private static extern void SherpaOnnxDestroyOnlineRecognizer(IntPtr handle);
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern IntPtr CreateOnlineStream(IntPtr handle);
|
||||
private static extern IntPtr SherpaOnnxCreateOnlineStream(IntPtr handle);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "IsOnlineStreamReady")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxIsOnlineStreamReady")]
|
||||
private static extern int IsReady(IntPtr handle, IntPtr stream);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "DecodeOnlineStream")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxDecodeOnlineStream")]
|
||||
private static extern void Decode(IntPtr handle, IntPtr stream);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "DecodeMultipleOnlineStreams")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxDecodeMultipleOnlineStreams")]
|
||||
private static extern void Decode(IntPtr handle, IntPtr[] streams, int n);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "GetOnlineStreamResult")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxGetOnlineStreamResult")]
|
||||
private static extern IntPtr GetResult(IntPtr handle, IntPtr stream);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "DestroyOnlineRecognizerResult")]
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxDestroyOnlineRecognizerResult")]
|
||||
private static extern void DestroyResult(IntPtr result);
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern void Reset(IntPtr handle, IntPtr stream);
|
||||
private static extern void SherpaOnnxOnlineStreamReset(IntPtr handle, IntPtr stream);
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern int IsEndpoint(IntPtr handle, IntPtr stream);
|
||||
private static extern int SherpaOnnxOnlineStreamIsEndpoint(IntPtr handle, IntPtr stream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@ namespace SherpaOnnx
|
||||
|
||||
public void AcceptWaveform(int sampleRate, float[] samples)
|
||||
{
|
||||
AcceptWaveform(Handle, sampleRate, samples, samples.Length);
|
||||
SherpaOnnxOnlineStreamAcceptWaveform(Handle, sampleRate, samples, samples.Length);
|
||||
}
|
||||
|
||||
public void InputFinished()
|
||||
{
|
||||
InputFinished(Handle);
|
||||
SherpaOnnxOnlineStreamInputFinished(Handle);
|
||||
}
|
||||
|
||||
~OnlineStream()
|
||||
@@ -39,7 +39,7 @@ namespace SherpaOnnx
|
||||
|
||||
private void Cleanup()
|
||||
{
|
||||
DestroyOnlineStream(Handle);
|
||||
SherpaOnnxDestroyOnlineStream(Handle);
|
||||
|
||||
// Don't permit the handle to be used again.
|
||||
_handle = new HandleRef(this, IntPtr.Zero);
|
||||
@@ -49,13 +49,13 @@ namespace SherpaOnnx
|
||||
public IntPtr Handle => _handle.Handle;
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern void DestroyOnlineStream(IntPtr handle);
|
||||
private static extern void SherpaOnnxDestroyOnlineStream(IntPtr handle);
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern void AcceptWaveform(IntPtr handle, int sampleRate, float[] samples, int n);
|
||||
private static extern void SherpaOnnxOnlineStreamAcceptWaveform(IntPtr handle, int sampleRate, float[] samples, int n);
|
||||
|
||||
[DllImport(Dll.Filename)]
|
||||
private static extern void InputFinished(IntPtr handle);
|
||||
private static extern void SherpaOnnxOnlineStreamInputFinished(IntPtr handle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ type OnlineStream struct {
|
||||
|
||||
// Free the internal pointer inside the recognizer to avoid memory leak.
|
||||
func DeleteOnlineRecognizer(recognizer *OnlineRecognizer) {
|
||||
C.DestroyOnlineRecognizer(recognizer.impl)
|
||||
C.SherpaOnnxDestroyOnlineRecognizer(recognizer.impl)
|
||||
recognizer.impl = nil
|
||||
}
|
||||
|
||||
@@ -224,14 +224,14 @@ func NewOnlineRecognizer(config *OnlineRecognizerConfig) *OnlineRecognizer {
|
||||
c.ctc_fst_decoder_config.max_active = C.int(config.CtcFstDecoderConfig.MaxActive)
|
||||
|
||||
recognizer := &OnlineRecognizer{}
|
||||
recognizer.impl = C.CreateOnlineRecognizer(&c)
|
||||
recognizer.impl = C.SherpaOnnxCreateOnlineRecognizer(&c)
|
||||
|
||||
return recognizer
|
||||
}
|
||||
|
||||
// Delete the internal pointer inside the stream to avoid memory leak.
|
||||
func DeleteOnlineStream(stream *OnlineStream) {
|
||||
C.DestroyOnlineStream(stream.impl)
|
||||
C.SherpaOnnxDestroyOnlineStream(stream.impl)
|
||||
stream.impl = nil
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ func DeleteOnlineStream(stream *OnlineStream) {
|
||||
// the returned stream to avoid memory leak
|
||||
func NewOnlineStream(recognizer *OnlineRecognizer) *OnlineStream {
|
||||
stream := &OnlineStream{}
|
||||
stream.impl = C.CreateOnlineStream(recognizer.impl)
|
||||
stream.impl = C.SherpaOnnxCreateOnlineStream(recognizer.impl)
|
||||
return stream
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ func NewOnlineStream(recognizer *OnlineRecognizer) *OnlineStream {
|
||||
//
|
||||
// samples contains audio samples. Each sample is in the range [-1, 1]
|
||||
func (s *OnlineStream) AcceptWaveform(sampleRate int, samples []float32) {
|
||||
C.AcceptWaveform(s.impl, C.int(sampleRate), (*C.float)(&samples[0]), C.int(len(samples)))
|
||||
C.SherpaOnnxOnlineStreamAcceptWaveform(s.impl, C.int(sampleRate), (*C.float)(&samples[0]), C.int(len(samples)))
|
||||
}
|
||||
|
||||
// Signal that there will be no incoming audio samples.
|
||||
@@ -260,7 +260,7 @@ func (s *OnlineStream) AcceptWaveform(sampleRate int, samples []float32) {
|
||||
// The main purpose of this function is to flush the remaining audio samples
|
||||
// buffered inside for feature extraction.
|
||||
func (s *OnlineStream) InputFinished() {
|
||||
C.InputFinished(s.impl)
|
||||
C.SherpaOnnxOnlineStreamInputFinished(s.impl)
|
||||
}
|
||||
|
||||
// Check whether the stream has enough feature frames for decoding.
|
||||
@@ -272,7 +272,7 @@ func (s *OnlineStream) InputFinished() {
|
||||
// recognizer.Decode(s)
|
||||
// }
|
||||
func (recognizer *OnlineRecognizer) IsReady(s *OnlineStream) bool {
|
||||
return C.IsOnlineStreamReady(recognizer.impl, s.impl) == 1
|
||||
return C.SherpaOnnxIsOnlineStreamReady(recognizer.impl, s.impl) == 1
|
||||
}
|
||||
|
||||
// Return true if an endpoint is detected.
|
||||
@@ -285,14 +285,14 @@ func (recognizer *OnlineRecognizer) IsReady(s *OnlineStream) bool {
|
||||
// recognizer.Reset(s)
|
||||
// }
|
||||
func (recognizer *OnlineRecognizer) IsEndpoint(s *OnlineStream) bool {
|
||||
return C.IsEndpoint(recognizer.impl, s.impl) == 1
|
||||
return C.SherpaOnnxOnlineStreamIsEndpoint(recognizer.impl, s.impl) == 1
|
||||
}
|
||||
|
||||
// After calling this function, the internal neural network model states
|
||||
// are reset and IsEndpoint(s) would return false. GetResult(s) would also
|
||||
// return an empty string.
|
||||
func (recognizer *OnlineRecognizer) Reset(s *OnlineStream) {
|
||||
C.Reset(recognizer.impl, s.impl)
|
||||
C.SherpaOnnxOnlineStreamReset(recognizer.impl, s.impl)
|
||||
}
|
||||
|
||||
// Decode the stream. Before calling this function, you have to ensure
|
||||
@@ -304,7 +304,7 @@ func (recognizer *OnlineRecognizer) Reset(s *OnlineStream) {
|
||||
// recognizer.Decode(s)
|
||||
// }
|
||||
func (recognizer *OnlineRecognizer) Decode(s *OnlineStream) {
|
||||
C.DecodeOnlineStream(recognizer.impl, s.impl)
|
||||
C.SherpaOnnxDecodeOnlineStream(recognizer.impl, s.impl)
|
||||
}
|
||||
|
||||
// Decode multiple streams in parallel, i.e., in batch.
|
||||
@@ -316,13 +316,13 @@ func (recognizer *OnlineRecognizer) DecodeStreams(s []*OnlineStream) {
|
||||
ss[i] = v.impl
|
||||
}
|
||||
|
||||
C.DecodeMultipleOnlineStreams(recognizer.impl, &ss[0], C.int(len(s)))
|
||||
C.SherpaOnnxDecodeMultipleOnlineStreams(recognizer.impl, &ss[0], C.int(len(s)))
|
||||
}
|
||||
|
||||
// Get the current result of stream since the last invoke of Reset()
|
||||
func (recognizer *OnlineRecognizer) GetResult(s *OnlineStream) *OnlineRecognizerResult {
|
||||
p := C.GetOnlineStreamResult(recognizer.impl, s.impl)
|
||||
defer C.DestroyOnlineRecognizerResult(p)
|
||||
p := C.SherpaOnnxGetOnlineStreamResult(recognizer.impl, s.impl)
|
||||
defer C.SherpaOnnxDestroyOnlineRecognizerResult(p)
|
||||
result := &OnlineRecognizerResult{}
|
||||
result.Text = C.GoString(p.text)
|
||||
|
||||
@@ -442,7 +442,7 @@ type OfflineRecognizerResult struct {
|
||||
|
||||
// Frees the internal pointer of the recognition to avoid memory leak.
|
||||
func DeleteOfflineRecognizer(recognizer *OfflineRecognizer) {
|
||||
C.DestroyOfflineRecognizer(recognizer.impl)
|
||||
C.SherpaOnnxDestroyOfflineRecognizer(recognizer.impl)
|
||||
recognizer.impl = nil
|
||||
}
|
||||
|
||||
@@ -537,14 +537,14 @@ func NewOfflineRecognizer(config *OfflineRecognizerConfig) *OfflineRecognizer {
|
||||
defer C.free(unsafe.Pointer(c.rule_fars))
|
||||
|
||||
recognizer := &OfflineRecognizer{}
|
||||
recognizer.impl = C.CreateOfflineRecognizer(&c)
|
||||
recognizer.impl = C.SherpaOnnxCreateOfflineRecognizer(&c)
|
||||
|
||||
return recognizer
|
||||
}
|
||||
|
||||
// Frees the internal pointer of the stream to avoid memory leak.
|
||||
func DeleteOfflineStream(stream *OfflineStream) {
|
||||
C.DestroyOfflineStream(stream.impl)
|
||||
C.SherpaOnnxDestroyOfflineStream(stream.impl)
|
||||
stream.impl = nil
|
||||
}
|
||||
|
||||
@@ -552,7 +552,7 @@ func DeleteOfflineStream(stream *OfflineStream) {
|
||||
// the returned stream to avoid memory leak
|
||||
func NewOfflineStream(recognizer *OfflineRecognizer) *OfflineStream {
|
||||
stream := &OfflineStream{}
|
||||
stream.impl = C.CreateOfflineStream(recognizer.impl)
|
||||
stream.impl = C.SherpaOnnxCreateOfflineStream(recognizer.impl)
|
||||
return stream
|
||||
}
|
||||
|
||||
@@ -564,12 +564,12 @@ func NewOfflineStream(recognizer *OfflineRecognizer) *OfflineStream {
|
||||
//
|
||||
// samples contains the actual audio samples. Each sample is in the range [-1, 1].
|
||||
func (s *OfflineStream) AcceptWaveform(sampleRate int, samples []float32) {
|
||||
C.AcceptWaveformOffline(s.impl, C.int(sampleRate), (*C.float)(&samples[0]), C.int(len(samples)))
|
||||
C.SherpaOnnxAcceptWaveformOffline(s.impl, C.int(sampleRate), (*C.float)(&samples[0]), C.int(len(samples)))
|
||||
}
|
||||
|
||||
// Decode the offline stream.
|
||||
func (recognizer *OfflineRecognizer) Decode(s *OfflineStream) {
|
||||
C.DecodeOfflineStream(recognizer.impl, s.impl)
|
||||
C.SherpaOnnxDecodeOfflineStream(recognizer.impl, s.impl)
|
||||
}
|
||||
|
||||
// Decode multiple streams in parallel, i.e., in batch.
|
||||
@@ -579,13 +579,13 @@ func (recognizer *OfflineRecognizer) DecodeStreams(s []*OfflineStream) {
|
||||
ss[i] = v.impl
|
||||
}
|
||||
|
||||
C.DecodeMultipleOfflineStreams(recognizer.impl, &ss[0], C.int(len(s)))
|
||||
C.SherpaOnnxDecodeMultipleOfflineStreams(recognizer.impl, &ss[0], C.int(len(s)))
|
||||
}
|
||||
|
||||
// Get the recognition result of the offline stream.
|
||||
func (s *OfflineStream) GetResult() *OfflineRecognizerResult {
|
||||
p := C.GetOfflineStreamResult(s.impl)
|
||||
defer C.DestroyOfflineRecognizerResult(p)
|
||||
p := C.SherpaOnnxGetOfflineStreamResult(s.impl)
|
||||
defer C.SherpaOnnxDestroyOfflineRecognizerResult(p)
|
||||
result := &OfflineRecognizerResult{}
|
||||
result.Text = C.GoString(p.text)
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ AudioTaggingCreateOfflineStreamWrapper(const Napi::CallbackInfo &info) {
|
||||
return Napi::External<SherpaOnnxOfflineStream>::New(
|
||||
env, const_cast<SherpaOnnxOfflineStream *>(stream),
|
||||
[](Napi::Env env, SherpaOnnxOfflineStream *stream) {
|
||||
DestroyOfflineStream(stream);
|
||||
SherpaOnnxDestroyOfflineStream(stream);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ static Napi::External<SherpaOnnxKeywordSpotter> CreateKeywordSpotterWrapper(
|
||||
SHERPA_ONNX_ASSIGN_ATTR_FLOAT(keywords_threshold, keywordsThreshold);
|
||||
SHERPA_ONNX_ASSIGN_ATTR_STR(keywords_file, keywordsFile);
|
||||
|
||||
SherpaOnnxKeywordSpotter *kws = CreateKeywordSpotter(&c);
|
||||
SherpaOnnxKeywordSpotter *kws = SherpaOnnxCreateKeywordSpotter(&c);
|
||||
|
||||
if (c.model_config.transducer.encoder) {
|
||||
delete[] c.model_config.transducer.encoder;
|
||||
@@ -95,7 +95,7 @@ static Napi::External<SherpaOnnxKeywordSpotter> CreateKeywordSpotterWrapper(
|
||||
|
||||
return Napi::External<SherpaOnnxKeywordSpotter>::New(
|
||||
env, kws, [](Napi::Env env, SherpaOnnxKeywordSpotter *kws) {
|
||||
DestroyKeywordSpotter(kws);
|
||||
SherpaOnnxDestroyKeywordSpotter(kws);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -122,11 +122,11 @@ static Napi::External<SherpaOnnxOnlineStream> CreateKeywordStreamWrapper(
|
||||
SherpaOnnxKeywordSpotter *kws =
|
||||
info[0].As<Napi::External<SherpaOnnxKeywordSpotter>>().Data();
|
||||
|
||||
SherpaOnnxOnlineStream *stream = CreateKeywordStream(kws);
|
||||
SherpaOnnxOnlineStream *stream = SherpaOnnxCreateKeywordStream(kws);
|
||||
|
||||
return Napi::External<SherpaOnnxOnlineStream>::New(
|
||||
env, stream, [](Napi::Env env, SherpaOnnxOnlineStream *stream) {
|
||||
DestroyOnlineStream(stream);
|
||||
SherpaOnnxDestroyOnlineStream(stream);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ static Napi::Boolean IsKeywordStreamReadyWrapper(
|
||||
SherpaOnnxOnlineStream *stream =
|
||||
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
|
||||
|
||||
int32_t is_ready = IsKeywordStreamReady(kws, stream);
|
||||
int32_t is_ready = SherpaOnnxIsKeywordStreamReady(kws, stream);
|
||||
|
||||
return Napi::Boolean::New(env, is_ready);
|
||||
}
|
||||
@@ -198,7 +198,7 @@ static void DecodeKeywordStreamWrapper(const Napi::CallbackInfo &info) {
|
||||
SherpaOnnxOnlineStream *stream =
|
||||
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
|
||||
|
||||
DecodeKeywordStream(kws, stream);
|
||||
SherpaOnnxDecodeKeywordStream(kws, stream);
|
||||
}
|
||||
|
||||
static Napi::String GetKeywordResultAsJsonWrapper(
|
||||
@@ -233,11 +233,11 @@ static Napi::String GetKeywordResultAsJsonWrapper(
|
||||
SherpaOnnxOnlineStream *stream =
|
||||
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
|
||||
|
||||
const char *json = GetKeywordResultAsJson(kws, stream);
|
||||
const char *json = SherpaOnnxGetKeywordResultAsJson(kws, stream);
|
||||
|
||||
Napi::String s = Napi::String::New(env, json);
|
||||
|
||||
FreeKeywordResultJson(json);
|
||||
SherpaOnnxFreeKeywordResultJson(json);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -202,7 +202,8 @@ CreateOfflineRecognizerWrapper(const Napi::CallbackInfo &info) {
|
||||
SHERPA_ONNX_ASSIGN_ATTR_STR(rule_fsts, ruleFsts);
|
||||
SHERPA_ONNX_ASSIGN_ATTR_STR(rule_fars, ruleFars);
|
||||
|
||||
SherpaOnnxOfflineRecognizer *recognizer = CreateOfflineRecognizer(&c);
|
||||
SherpaOnnxOfflineRecognizer *recognizer =
|
||||
SherpaOnnxCreateOfflineRecognizer(&c);
|
||||
|
||||
if (c.model_config.transducer.encoder) {
|
||||
delete[] c.model_config.transducer.encoder;
|
||||
@@ -306,7 +307,7 @@ CreateOfflineRecognizerWrapper(const Napi::CallbackInfo &info) {
|
||||
return Napi::External<SherpaOnnxOfflineRecognizer>::New(
|
||||
env, recognizer,
|
||||
[](Napi::Env env, SherpaOnnxOfflineRecognizer *recognizer) {
|
||||
DestroyOfflineRecognizer(recognizer);
|
||||
SherpaOnnxDestroyOfflineRecognizer(recognizer);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -334,11 +335,11 @@ static Napi::External<SherpaOnnxOfflineStream> CreateOfflineStreamWrapper(
|
||||
SherpaOnnxOfflineRecognizer *recognizer =
|
||||
info[0].As<Napi::External<SherpaOnnxOfflineRecognizer>>().Data();
|
||||
|
||||
SherpaOnnxOfflineStream *stream = CreateOfflineStream(recognizer);
|
||||
SherpaOnnxOfflineStream *stream = SherpaOnnxCreateOfflineStream(recognizer);
|
||||
|
||||
return Napi::External<SherpaOnnxOfflineStream>::New(
|
||||
env, stream, [](Napi::Env env, SherpaOnnxOfflineStream *stream) {
|
||||
DestroyOfflineStream(stream);
|
||||
SherpaOnnxDestroyOfflineStream(stream);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -405,8 +406,8 @@ static void AcceptWaveformOfflineWrapper(const Napi::CallbackInfo &info) {
|
||||
Napi::Float32Array samples = obj.Get("samples").As<Napi::Float32Array>();
|
||||
int32_t sample_rate = obj.Get("sampleRate").As<Napi::Number>().Int32Value();
|
||||
|
||||
AcceptWaveformOffline(stream, sample_rate, samples.Data(),
|
||||
samples.ElementLength());
|
||||
SherpaOnnxAcceptWaveformOffline(stream, sample_rate, samples.Data(),
|
||||
samples.ElementLength());
|
||||
}
|
||||
|
||||
static void DecodeOfflineStreamWrapper(const Napi::CallbackInfo &info) {
|
||||
@@ -441,7 +442,7 @@ static void DecodeOfflineStreamWrapper(const Napi::CallbackInfo &info) {
|
||||
SherpaOnnxOfflineStream *stream =
|
||||
info[1].As<Napi::External<SherpaOnnxOfflineStream>>().Data();
|
||||
|
||||
DecodeOfflineStream(recognizer, stream);
|
||||
SherpaOnnxDecodeOfflineStream(recognizer, stream);
|
||||
}
|
||||
|
||||
static Napi::String GetOfflineStreamResultAsJsonWrapper(
|
||||
@@ -466,10 +467,10 @@ static Napi::String GetOfflineStreamResultAsJsonWrapper(
|
||||
SherpaOnnxOfflineStream *stream =
|
||||
info[0].As<Napi::External<SherpaOnnxOfflineStream>>().Data();
|
||||
|
||||
const char *json = GetOfflineStreamResultAsJson(stream);
|
||||
const char *json = SherpaOnnxGetOfflineStreamResultAsJson(stream);
|
||||
Napi::String s = Napi::String::New(env, json);
|
||||
|
||||
DestroyOfflineStreamResultJson(json);
|
||||
SherpaOnnxDestroyOfflineStreamResultJson(json);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ SpeakerEmbeddingExtractorCreateStreamWrapper(const Napi::CallbackInfo &info) {
|
||||
return Napi::External<SherpaOnnxOnlineStream>::New(
|
||||
env, const_cast<SherpaOnnxOnlineStream *>(stream),
|
||||
[](Napi::Env env, SherpaOnnxOnlineStream *stream) {
|
||||
DestroyOnlineStream(stream);
|
||||
SherpaOnnxDestroyOnlineStream(stream);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ SpokenLanguageIdentificationCreateOfflineStreamWrapper(
|
||||
|
||||
return Napi::External<SherpaOnnxOfflineStream>::New(
|
||||
env, stream, [](Napi::Env env, SherpaOnnxOfflineStream *stream) {
|
||||
DestroyOfflineStream(stream);
|
||||
SherpaOnnxDestroyOfflineStream(stream);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ static Napi::External<SherpaOnnxOnlineRecognizer> CreateOnlineRecognizerWrapper(
|
||||
|
||||
c.ctc_fst_decoder_config = GetCtcFstDecoderConfig(o);
|
||||
|
||||
SherpaOnnxOnlineRecognizer *recognizer = CreateOnlineRecognizer(&c);
|
||||
SherpaOnnxOnlineRecognizer *recognizer = SherpaOnnxCreateOnlineRecognizer(&c);
|
||||
|
||||
if (c.model_config.transducer.encoder) {
|
||||
delete[] c.model_config.transducer.encoder;
|
||||
@@ -270,7 +270,7 @@ static Napi::External<SherpaOnnxOnlineRecognizer> CreateOnlineRecognizerWrapper(
|
||||
return Napi::External<SherpaOnnxOnlineRecognizer>::New(
|
||||
env, recognizer,
|
||||
[](Napi::Env env, SherpaOnnxOnlineRecognizer *recognizer) {
|
||||
DestroyOnlineRecognizer(recognizer);
|
||||
SherpaOnnxDestroyOnlineRecognizer(recognizer);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -298,11 +298,11 @@ static Napi::External<SherpaOnnxOnlineStream> CreateOnlineStreamWrapper(
|
||||
SherpaOnnxOnlineRecognizer *recognizer =
|
||||
info[0].As<Napi::External<SherpaOnnxOnlineRecognizer>>().Data();
|
||||
|
||||
SherpaOnnxOnlineStream *stream = CreateOnlineStream(recognizer);
|
||||
SherpaOnnxOnlineStream *stream = SherpaOnnxCreateOnlineStream(recognizer);
|
||||
|
||||
return Napi::External<SherpaOnnxOnlineStream>::New(
|
||||
env, stream, [](Napi::Env env, SherpaOnnxOnlineStream *stream) {
|
||||
DestroyOnlineStream(stream);
|
||||
SherpaOnnxDestroyOnlineStream(stream);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -369,7 +369,8 @@ static void AcceptWaveformWrapper(const Napi::CallbackInfo &info) {
|
||||
Napi::Float32Array samples = obj.Get("samples").As<Napi::Float32Array>();
|
||||
int32_t sample_rate = obj.Get("sampleRate").As<Napi::Number>().Int32Value();
|
||||
|
||||
AcceptWaveform(stream, sample_rate, samples.Data(), samples.ElementLength());
|
||||
SherpaOnnxOnlineStreamAcceptWaveform(stream, sample_rate, samples.Data(),
|
||||
samples.ElementLength());
|
||||
}
|
||||
|
||||
static Napi::Boolean IsOnlineStreamReadyWrapper(
|
||||
@@ -405,7 +406,7 @@ static Napi::Boolean IsOnlineStreamReadyWrapper(
|
||||
SherpaOnnxOnlineStream *stream =
|
||||
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
|
||||
|
||||
int32_t is_ready = IsOnlineStreamReady(recognizer, stream);
|
||||
int32_t is_ready = SherpaOnnxIsOnlineStreamReady(recognizer, stream);
|
||||
|
||||
return Napi::Boolean::New(env, is_ready);
|
||||
}
|
||||
@@ -442,7 +443,7 @@ static void DecodeOnlineStreamWrapper(const Napi::CallbackInfo &info) {
|
||||
SherpaOnnxOnlineStream *stream =
|
||||
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
|
||||
|
||||
DecodeOnlineStream(recognizer, stream);
|
||||
SherpaOnnxDecodeOnlineStream(recognizer, stream);
|
||||
}
|
||||
|
||||
static Napi::String GetOnlineStreamResultAsJsonWrapper(
|
||||
@@ -478,10 +479,10 @@ static Napi::String GetOnlineStreamResultAsJsonWrapper(
|
||||
SherpaOnnxOnlineStream *stream =
|
||||
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
|
||||
|
||||
const char *json = GetOnlineStreamResultAsJson(recognizer, stream);
|
||||
const char *json = SherpaOnnxGetOnlineStreamResultAsJson(recognizer, stream);
|
||||
Napi::String s = Napi::String::New(env, json);
|
||||
|
||||
DestroyOnlineStreamResultJson(json);
|
||||
SherpaOnnxDestroyOnlineStreamResultJson(json);
|
||||
|
||||
return s;
|
||||
}
|
||||
@@ -508,7 +509,7 @@ static void InputFinishedWrapper(const Napi::CallbackInfo &info) {
|
||||
SherpaOnnxOnlineStream *stream =
|
||||
info[0].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
|
||||
|
||||
InputFinished(stream);
|
||||
SherpaOnnxOnlineStreamInputFinished(stream);
|
||||
}
|
||||
|
||||
static void ResetOnlineStreamWrapper(const Napi::CallbackInfo &info) {
|
||||
@@ -543,7 +544,7 @@ static void ResetOnlineStreamWrapper(const Napi::CallbackInfo &info) {
|
||||
SherpaOnnxOnlineStream *stream =
|
||||
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
|
||||
|
||||
Reset(recognizer, stream);
|
||||
SherpaOnnxOnlineStreamReset(recognizer, stream);
|
||||
}
|
||||
|
||||
static Napi::Boolean IsEndpointWrapper(const Napi::CallbackInfo &info) {
|
||||
@@ -578,7 +579,7 @@ static Napi::Boolean IsEndpointWrapper(const Napi::CallbackInfo &info) {
|
||||
SherpaOnnxOnlineStream *stream =
|
||||
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
|
||||
|
||||
int32_t is_endpoint = IsEndpoint(recognizer, stream);
|
||||
int32_t is_endpoint = SherpaOnnxOnlineStreamIsEndpoint(recognizer, stream);
|
||||
|
||||
return Napi::Boolean::New(env, is_endpoint);
|
||||
}
|
||||
@@ -603,12 +604,12 @@ static Napi::External<SherpaOnnxDisplay> CreateDisplayWrapper(
|
||||
}
|
||||
int32_t max_word_per_line = info[0].As<Napi::Number>().Int32Value();
|
||||
|
||||
const SherpaOnnxDisplay *display = CreateDisplay(max_word_per_line);
|
||||
const SherpaOnnxDisplay *display = SherpaOnnxCreateDisplay(max_word_per_line);
|
||||
|
||||
return Napi::External<SherpaOnnxDisplay>::New(
|
||||
env, const_cast<SherpaOnnxDisplay *>(display),
|
||||
[](Napi::Env env, SherpaOnnxDisplay *display) {
|
||||
DestroyDisplay(display);
|
||||
SherpaOnnxDestroyDisplay(display);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user