Refactor C API to prefix each API with SherpaOnnx. (#1171)
This commit is contained in:
@@ -9,22 +9,22 @@ endif()
|
||||
set(exported_functions
|
||||
MyPrint
|
||||
# online ASR
|
||||
AcceptWaveform
|
||||
CreateOnlineRecognizer
|
||||
CreateOnlineStream
|
||||
DecodeOnlineStream
|
||||
DestroyOfflineStreamResultJson
|
||||
DestroyOnlineRecognizer
|
||||
DestroyOnlineRecognizerResult
|
||||
DestroyOnlineStream
|
||||
DestroyOnlineStreamResultJson
|
||||
GetOfflineStreamResultAsJson
|
||||
GetOnlineStreamResult
|
||||
GetOnlineStreamResultAsJson
|
||||
InputFinished
|
||||
IsEndpoint
|
||||
IsOnlineStreamReady
|
||||
Reset
|
||||
SherpaOnnxCreateOnlineRecognizer
|
||||
SherpaOnnxCreateOnlineStream
|
||||
SherpaOnnxDecodeOnlineStream
|
||||
SherpaOnnxDestroyOfflineStreamResultJson
|
||||
SherpaOnnxDestroyOnlineRecognizer
|
||||
SherpaOnnxDestroyOnlineRecognizerResult
|
||||
SherpaOnnxDestroyOnlineStream
|
||||
SherpaOnnxDestroyOnlineStreamResultJson
|
||||
SherpaOnnxGetOfflineStreamResultAsJson
|
||||
SherpaOnnxGetOnlineStreamResult
|
||||
SherpaOnnxGetOnlineStreamResultAsJson
|
||||
SherpaOnnxIsOnlineStreamReady
|
||||
SherpaOnnxOnlineStreamAcceptWaveform
|
||||
SherpaOnnxOnlineStreamInputFinished
|
||||
SherpaOnnxOnlineStreamIsEndpoint
|
||||
SherpaOnnxOnlineStreamReset
|
||||
#
|
||||
)
|
||||
set(mangled_exported_functions)
|
||||
|
||||
@@ -869,7 +869,7 @@ class OfflineStream {
|
||||
|
||||
free() {
|
||||
if (this.handle) {
|
||||
this.Module._DestroyOfflineStream(this.handle);
|
||||
this.Module._SherpaOnnxDestroyOfflineStream(this.handle);
|
||||
this.handle = null;
|
||||
}
|
||||
}
|
||||
@@ -882,7 +882,7 @@ class OfflineStream {
|
||||
const pointer =
|
||||
this.Module._malloc(samples.length * samples.BYTES_PER_ELEMENT);
|
||||
this.Module.HEAPF32.set(samples, pointer / samples.BYTES_PER_ELEMENT);
|
||||
this.Module._AcceptWaveformOffline(
|
||||
this.Module._SherpaOnnxAcceptWaveformOffline(
|
||||
this.handle, sampleRate, pointer, samples.length);
|
||||
this.Module._free(pointer);
|
||||
}
|
||||
@@ -892,7 +892,7 @@ class OfflineRecognizer {
|
||||
constructor(configObj, Module) {
|
||||
this.config = configObj;
|
||||
const config = initSherpaOnnxOfflineRecognizerConfig(configObj, Module);
|
||||
const handle = Module._CreateOfflineRecognizer(config.ptr);
|
||||
const handle = Module._SherpaOnnxCreateOfflineRecognizer(config.ptr);
|
||||
freeConfig(config, Module);
|
||||
|
||||
this.handle = handle;
|
||||
@@ -900,24 +900,25 @@ class OfflineRecognizer {
|
||||
}
|
||||
|
||||
free() {
|
||||
this.Module._DestroyOfflineRecognizer(this.handle);
|
||||
this.Module._SherpaOnnxDestroyOfflineRecognizer(this.handle);
|
||||
this.handle = 0
|
||||
}
|
||||
|
||||
createStream() {
|
||||
const handle = this.Module._CreateOfflineStream(this.handle);
|
||||
const handle = this.Module._SherpaOnnxCreateOfflineStream(this.handle);
|
||||
return new OfflineStream(handle, this.Module);
|
||||
}
|
||||
|
||||
decode(stream) {
|
||||
this.Module._DecodeOfflineStream(this.handle, stream.handle);
|
||||
this.Module._SherpaOnnxDecodeOfflineStream(this.handle, stream.handle);
|
||||
}
|
||||
|
||||
getResult(stream) {
|
||||
const r = this.Module._GetOfflineStreamResultAsJson(stream.handle);
|
||||
const r =
|
||||
this.Module._SherpaOnnxGetOfflineStreamResultAsJson(stream.handle);
|
||||
const jsonStr = this.Module.UTF8ToString(r);
|
||||
const ans = JSON.parse(jsonStr);
|
||||
this.Module._DestroyOfflineStreamResultJson(r);
|
||||
this.Module._SherpaOnnxDestroyOfflineStreamResultJson(r);
|
||||
|
||||
return ans;
|
||||
}
|
||||
@@ -933,7 +934,7 @@ class OnlineStream {
|
||||
|
||||
free() {
|
||||
if (this.handle) {
|
||||
this.Module._DestroyOnlineStream(this.handle);
|
||||
this.Module._SherpaOnnxDestroyOnlineStream(this.handle);
|
||||
this.handle = null;
|
||||
this.Module._free(this.pointer);
|
||||
this.pointer = null;
|
||||
@@ -954,12 +955,12 @@ class OnlineStream {
|
||||
}
|
||||
|
||||
this.Module.HEAPF32.set(samples, this.pointer / samples.BYTES_PER_ELEMENT);
|
||||
this.Module._AcceptWaveform(
|
||||
this.Module._SherpaOnnxOnlineStreamAcceptWaveform(
|
||||
this.handle, sampleRate, this.pointer, samples.length);
|
||||
}
|
||||
|
||||
inputFinished() {
|
||||
this.Module._InputFinished(this.handle);
|
||||
this.Module._SherpaOnnxOnlineStreamInputFinished(this.handle);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -967,7 +968,7 @@ class OnlineRecognizer {
|
||||
constructor(configObj, Module) {
|
||||
this.config = configObj;
|
||||
const config = initSherpaOnnxOnlineRecognizerConfig(configObj, Module)
|
||||
const handle = Module._CreateOnlineRecognizer(config.ptr);
|
||||
const handle = Module._SherpaOnnxCreateOnlineRecognizer(config.ptr);
|
||||
|
||||
freeConfig(config, Module);
|
||||
|
||||
@@ -976,37 +977,39 @@ class OnlineRecognizer {
|
||||
}
|
||||
|
||||
free() {
|
||||
this.Module._DestroyOnlineRecognizer(this.handle);
|
||||
this.Module._SherpaOnnxDestroyOnlineRecognizer(this.handle);
|
||||
this.handle = 0
|
||||
}
|
||||
|
||||
createStream() {
|
||||
const handle = this.Module._CreateOnlineStream(this.handle);
|
||||
const handle = this.Module._SherpaOnnxCreateOnlineStream(this.handle);
|
||||
return new OnlineStream(handle, this.Module);
|
||||
}
|
||||
|
||||
isReady(stream) {
|
||||
return this.Module._IsOnlineStreamReady(this.handle, stream.handle) == 1;
|
||||
return this.Module._SherpaOnnxIsOnlineStreamReady(
|
||||
this.handle, stream.handle) == 1;
|
||||
}
|
||||
|
||||
decode(stream) {
|
||||
this.Module._DecodeOnlineStream(this.handle, stream.handle);
|
||||
this.Module._SherpaOnnxDecodeOnlineStream(this.handle, stream.handle);
|
||||
}
|
||||
|
||||
isEndpoint(stream) {
|
||||
return this.Module._IsEndpoint(this.handle, stream.handle) == 1;
|
||||
return this.Module._SherpaOnnxOnlineStreamIsEndpoint(
|
||||
this.handle, stream.handle) == 1;
|
||||
}
|
||||
|
||||
reset(stream) {
|
||||
this.Module._Reset(this.handle, stream.handle);
|
||||
this.Module._SherpaOnnxOnlineStreamReset(this.handle, stream.handle);
|
||||
}
|
||||
|
||||
getResult(stream) {
|
||||
const r =
|
||||
this.Module._GetOnlineStreamResultAsJson(this.handle, stream.handle);
|
||||
const r = this.Module._SherpaOnnxGetOnlineStreamResultAsJson(
|
||||
this.handle, stream.handle);
|
||||
const jsonStr = this.Module.UTF8ToString(r);
|
||||
const ans = JSON.parse(jsonStr);
|
||||
this.Module._DestroyOnlineStreamResultJson(r);
|
||||
this.Module._SherpaOnnxDestroyOnlineStreamResultJson(r);
|
||||
|
||||
return ans;
|
||||
}
|
||||
|
||||
@@ -8,15 +8,15 @@ if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/assets/decoder-epoch-12-avg-2-chunk-1
|
||||
endif()
|
||||
|
||||
set(exported_functions
|
||||
AcceptWaveform
|
||||
CreateKeywordSpotter
|
||||
DestroyKeywordSpotter
|
||||
CreateKeywordStream
|
||||
DecodeKeywordStream
|
||||
GetKeywordResult
|
||||
DestroyKeywordResult
|
||||
IsKeywordStreamReady
|
||||
InputFinished
|
||||
SherpaOnnxCreateKeywordSpotter
|
||||
SherpaOnnxCreateKeywordStream
|
||||
SherpaOnnxDecodeKeywordStream
|
||||
SherpaOnnxDestroyKeywordResult
|
||||
SherpaOnnxDestroyKeywordSpotter
|
||||
SherpaOnnxGetKeywordResult
|
||||
SherpaOnnxIsKeywordStreamReady
|
||||
SherpaOnnxOnlineStreamAcceptWaveform
|
||||
SherpaOnnxOnlineStreamInputFinished
|
||||
)
|
||||
set(mangled_exported_functions)
|
||||
foreach(x IN LISTS exported_functions)
|
||||
|
||||
@@ -189,7 +189,7 @@ class Stream {
|
||||
|
||||
free() {
|
||||
if (this.handle) {
|
||||
this.Module._DestroyOnlineKwsStream(this.handle);
|
||||
this.Module._SherpaOnnxDestroyOnlineStream(this.handle);
|
||||
this.handle = null;
|
||||
this.Module._free(this.pointer);
|
||||
this.pointer = null;
|
||||
@@ -210,12 +210,12 @@ class Stream {
|
||||
}
|
||||
|
||||
this.Module.HEAPF32.set(samples, this.pointer / samples.BYTES_PER_ELEMENT);
|
||||
this.Module._AcceptWaveform(
|
||||
this.Module._SherpaOnnxOnlineStreamAcceptWaveform(
|
||||
this.handle, sampleRate, this.pointer, samples.length);
|
||||
}
|
||||
|
||||
inputFinished() {
|
||||
this.Module._InputFinished(this.handle);
|
||||
this.Module._SherpaOnnxOnlineStreamInputFinished(this.handle);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -223,7 +223,7 @@ class Kws {
|
||||
constructor(configObj, Module) {
|
||||
this.config = configObj;
|
||||
let config = initKwsConfig(configObj, Module)
|
||||
let handle = Module._CreateKeywordSpotter(config.ptr);
|
||||
let handle = Module._SherpaOnnxCreateKeywordSpotter(config.ptr);
|
||||
|
||||
freeConfig(config, Module);
|
||||
|
||||
@@ -232,28 +232,30 @@ class Kws {
|
||||
}
|
||||
|
||||
free() {
|
||||
this.Module._DestroyKeywordSpotter(this.handle);
|
||||
this.Module._SherpaOnnxDestroyKeywordSpotter(this.handle);
|
||||
this.handle = 0
|
||||
}
|
||||
|
||||
createStream() {
|
||||
let handle = this.Module._CreateKeywordStream(this.handle);
|
||||
let handle = this.Module._SherpaOnnxCreateKeywordStream(this.handle);
|
||||
return new Stream(handle, this.Module);
|
||||
}
|
||||
|
||||
isReady(stream) {
|
||||
return this.Module._IsKeywordStreamReady(this.handle, stream.handle) === 1;
|
||||
return this.Module._SherpaOnnxIsKeywordStreamReady(
|
||||
this.handle, stream.handle) == 1;
|
||||
}
|
||||
|
||||
decode(stream) {
|
||||
return this.Module._DecodeKeywordStream(this.handle, stream.handle);
|
||||
return this.Module._SherpaOnnxDecodeKeywordStream(
|
||||
this.handle, stream.handle);
|
||||
}
|
||||
|
||||
getResult(stream) {
|
||||
let r = this.Module._GetKeywordResult(this.handle, stream.handle);
|
||||
let r = this.Module._SherpaOnnxGetKeywordResult(this.handle, stream.handle);
|
||||
let jsonPtr = this.Module.getValue(r + 24, 'i8*');
|
||||
let json = this.Module.UTF8ToString(jsonPtr);
|
||||
this.Module._DestroyKeywordResult(r);
|
||||
this.Module._SherpaOnnxDestroyKeywordResult(r);
|
||||
return JSON.parse(json);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,41 +14,41 @@ set(exported_functions
|
||||
SherpaOnnxOfflineTtsSampleRate
|
||||
SherpaOnnxWriteWave
|
||||
# streaming asr
|
||||
AcceptWaveform
|
||||
CreateOnlineRecognizer
|
||||
CreateOnlineStream
|
||||
DecodeOnlineStream
|
||||
DestroyOnlineRecognizer
|
||||
DestroyOnlineRecognizerResult
|
||||
DestroyOnlineStream
|
||||
DestroyOnlineStreamResultJson
|
||||
GetOnlineStreamResult
|
||||
GetOnlineStreamResultAsJson
|
||||
InputFinished
|
||||
IsEndpoint
|
||||
IsOnlineStreamReady
|
||||
Reset
|
||||
SherpaOnnxCreateOnlineRecognizer
|
||||
SherpaOnnxCreateOnlineStream
|
||||
SherpaOnnxDecodeOnlineStream
|
||||
SherpaOnnxDestroyOnlineRecognizer
|
||||
SherpaOnnxDestroyOnlineRecognizerResult
|
||||
SherpaOnnxDestroyOnlineStream
|
||||
SherpaOnnxDestroyOnlineStreamResultJson
|
||||
SherpaOnnxGetOnlineStreamResult
|
||||
SherpaOnnxGetOnlineStreamResultAsJson
|
||||
SherpaOnnxIsOnlineStreamReady
|
||||
SherpaOnnxOnlineStreamAcceptWaveform
|
||||
SherpaOnnxOnlineStreamInputFinished
|
||||
SherpaOnnxOnlineStreamIsEndpoint
|
||||
SherpaOnnxOnlineStreamReset
|
||||
# non-streaming ASR
|
||||
AcceptWaveformOffline
|
||||
CreateOfflineRecognizer
|
||||
CreateOfflineStream
|
||||
DecodeMultipleOfflineStreams
|
||||
DecodeOfflineStream
|
||||
DestroyOfflineRecognizer
|
||||
DestroyOfflineRecognizerResult
|
||||
DestroyOfflineStream
|
||||
DestroyOfflineStreamResultJson
|
||||
GetOfflineStreamResult
|
||||
GetOfflineStreamResultAsJson
|
||||
PrintOfflineRecognizerConfig
|
||||
SherpaOnnxAcceptWaveformOffline
|
||||
SherpaOnnxCreateOfflineRecognizer
|
||||
SherpaOnnxCreateOfflineStream
|
||||
SherpaOnnxDecodeMultipleOfflineStreams
|
||||
SherpaOnnxDecodeOfflineStream
|
||||
SherpaOnnxDestroyOfflineRecognizer
|
||||
SherpaOnnxDestroyOfflineRecognizerResult
|
||||
SherpaOnnxDestroyOfflineStream
|
||||
SherpaOnnxDestroyOfflineStreamResultJson
|
||||
SherpaOnnxGetOfflineStreamResult
|
||||
SherpaOnnxGetOfflineStreamResultAsJson
|
||||
# online kws
|
||||
CreateKeywordSpotter
|
||||
DestroyKeywordSpotter
|
||||
CreateKeywordStream
|
||||
DecodeKeywordStream
|
||||
GetKeywordResult
|
||||
DestroyKeywordResult
|
||||
IsKeywordStreamReady
|
||||
SherpaOnnxCreateKeywordSpotter
|
||||
SherpaOnnxCreateKeywordStream
|
||||
SherpaOnnxDecodeKeywordStream
|
||||
SherpaOnnxDestroyKeywordResult
|
||||
SherpaOnnxDestroyKeywordSpotter
|
||||
SherpaOnnxGetKeywordResult
|
||||
SherpaOnnxIsKeywordStreamReady
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user