Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
sherpaonnx
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Grey Faulkenberry, MD MPH
2025-02-13 02:57:06 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2025-02-13 15:57:06 +0800
Commit
115e9c224739647db51103b568fcd0df782b5672
115e9c22
1 parent
ce7c03b0
Flutter OnlinePunctuation (#1854)
隐藏空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
168 行增加
和
1 行删除
flutter/sherpa_onnx/lib/sherpa_onnx.dart
flutter/sherpa_onnx/lib/src/punctuation.dart → flutter/sherpa_onnx/lib/src/offline_punctuation.dart
flutter/sherpa_onnx/lib/src/online_punctuation.dart
flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart
flutter/sherpa_onnx/lib/sherpa_onnx.dart
查看文件 @
115e9c2
...
...
@@ -5,12 +5,13 @@ import 'dart:ffi';
export
'src/audio_tagging.dart'
;
export
'src/feature_config.dart'
;
export
'src/keyword_spotter.dart'
;
export
'src/offline_punctuation.dart'
;
export
'src/offline_recognizer.dart'
;
export
'src/offline_speaker_diarization.dart'
;
export
'src/offline_stream.dart'
;
export
'src/online_punctuation.dart'
;
export
'src/online_recognizer.dart'
;
export
'src/online_stream.dart'
;
export
'src/punctuation.dart'
;
export
'src/speaker_identification.dart'
;
export
'src/tts.dart'
;
export
'src/vad.dart'
;
...
...
flutter/sherpa_onnx/lib/src/punctuation.dart → flutter/sherpa_onnx/lib/src/
offline_
punctuation.dart
查看文件 @
115e9c2
flutter/sherpa_onnx/lib/src/online_punctuation.dart
0 → 100644
查看文件 @
115e9c2
import
'dart:ffi'
;
import
'package:ffi/ffi.dart'
;
import
'./sherpa_onnx_bindings.dart'
;
class
OnlinePunctuationModelConfig
{
OnlinePunctuationModelConfig
(
{
required
this
.
cnnBiLstm
,
required
this
.
bpeVocab
,
this
.
numThreads
=
1
,
this
.
provider
=
'cpu'
,
this
.
debug
=
true
});
@override
String
toString
()
{
return
'OnlinePunctuationModelConfig(cnnBiLstm:
$cnnBiLstm
, '
'bpeVocab:
$bpeVocab
, numThreads:
$numThreads
, '
'provider:
$provider
, debug:
$debug
)'
;
}
final
String
cnnBiLstm
;
final
String
bpeVocab
;
final
int
numThreads
;
final
String
provider
;
final
bool
debug
;
}
class
OnlinePunctuationConfig
{
OnlinePunctuationConfig
({
required
this
.
model
,
});
@override
String
toString
()
{
return
'OnlinePunctuationConfig(model:
$model
)'
;
}
final
OnlinePunctuationModelConfig
model
;
}
class
OnlinePunctuation
{
OnlinePunctuation
.
fromPtr
({
required
this
.
ptr
,
required
this
.
config
});
OnlinePunctuation
.
_
({
required
this
.
ptr
,
required
this
.
config
});
// The user has to invoke OnlinePunctuation.free() to avoid memory leak.
factory
OnlinePunctuation
({
required
OnlinePunctuationConfig
config
})
{
final
c
=
calloc
<
SherpaOnnxOnlinePunctuationConfig
>();
final
cnnBiLstmPtr
=
config
.
model
.
cnnBiLstm
.
toNativeUtf8
();
final
bpeVocabPtr
=
config
.
model
.
bpeVocab
.
toNativeUtf8
();
c
.
ref
.
model
.
cnnBiLstm
=
cnnBiLstmPtr
;
c
.
ref
.
model
.
bpeVocab
=
bpeVocabPtr
;
c
.
ref
.
model
.
numThreads
=
config
.
model
.
numThreads
;
c
.
ref
.
model
.
debug
=
config
.
model
.
debug
?
1
:
0
;
final
providerPtr
=
config
.
model
.
provider
.
toNativeUtf8
();
c
.
ref
.
model
.
provider
=
providerPtr
;
final
ptr
=
SherpaOnnxBindings
.
sherpaOnnxCreateOnlinePunctuation
?.
call
(
c
)
??
nullptr
;
// Free the allocated strings and struct memory
calloc
.
free
(
providerPtr
);
calloc
.
free
(
cnnBiLstmPtr
);
calloc
.
free
(
bpeVocabPtr
);
calloc
.
free
(
c
);
return
OnlinePunctuation
.
_
(
ptr:
ptr
,
config:
config
);
}
void
free
()
{
SherpaOnnxBindings
.
sherpaOnnxDestroyOnlinePunctuation
?.
call
(
ptr
);
ptr
=
nullptr
;
}
String
addPunct
(
String
text
)
{
final
textPtr
=
text
.
toNativeUtf8
();
final
p
=
SherpaOnnxBindings
.
sherpaOnnxOnlinePunctuationAddPunct
?.
call
(
ptr
,
textPtr
)
??
nullptr
;
calloc
.
free
(
textPtr
);
if
(
p
==
nullptr
)
{
return
''
;
}
final
ans
=
p
.
toDartString
();
SherpaOnnxBindings
.
sherpaOnnxOnlinePunctuationFreeText
?.
call
(
p
);
return
ans
;
}
Pointer
<
SherpaOnnxOnlinePunctuation
>
ptr
;
final
OnlinePunctuationConfig
config
;
}
...
...
flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart
查看文件 @
115e9c2
...
...
@@ -78,6 +78,20 @@ final class SherpaOnnxOfflinePunctuationConfig extends Struct {
external
SherpaOnnxOfflinePunctuationModelConfig
model
;
}
final
class
SherpaOnnxOnlinePunctuationModelConfig
extends
Struct
{
external
Pointer
<
Utf8
>
cnnBiLstm
;
external
Pointer
<
Utf8
>
bpeVocab
;
@Int32
()
external
int
numThreads
;
@Int32
()
external
int
debug
;
external
Pointer
<
Utf8
>
provider
;
}
final
class
SherpaOnnxOnlinePunctuationConfig
extends
Struct
{
external
SherpaOnnxOnlinePunctuationModelConfig
model
;
}
final
class
SherpaOnnxOfflineZipformerAudioTaggingModelConfig
extends
Struct
{
external
Pointer
<
Utf8
>
model
;
}
...
...
@@ -469,6 +483,8 @@ final class SherpaOnnxKeywordSpotterConfig extends Struct {
final
class
SherpaOnnxOfflinePunctuation
extends
Opaque
{}
final
class
SherpaOnnxOnlinePunctuation
extends
Opaque
{}
final
class
SherpaOnnxAudioTagging
extends
Opaque
{}
final
class
SherpaOnnxKeywordSpotter
extends
Opaque
{}
...
...
@@ -512,6 +528,10 @@ typedef SherpaOnnxCreateOfflinePunctuationNative
=
Pointer
<
SherpaOnnxOfflinePunctuation
>
Function
(
Pointer
<
SherpaOnnxOfflinePunctuationConfig
>);
typedef
SherpaOnnxCreateOnlinePunctuationNative
=
Pointer
<
SherpaOnnxOnlinePunctuation
>
Function
(
Pointer
<
SherpaOnnxOnlinePunctuationConfig
>);
typedef
SherpaOnnxOfflineSpeakerDiarizationGetSampleRateNative
=
Int32
Function
(
Pointer
<
SherpaOnnxOfflineSpeakerDiarization
>);
...
...
@@ -605,6 +625,26 @@ typedef SherpaOfflinePunctuationFreeTextNative = Void Function(Pointer<Utf8>);
typedef
SherpaOfflinePunctuationFreeText
=
void
Function
(
Pointer
<
Utf8
>);
typedef
SherpaOnnxCreateOnlinePunctuation
=
SherpaOnnxCreateOnlinePunctuationNative
;
typedef
SherpaOnnxDestroyOnlinePunctuationNative
=
Void
Function
(
Pointer
<
SherpaOnnxOnlinePunctuation
>);
typedef
SherpaOnnxDestroyOnlinePunctuation
=
void
Function
(
Pointer
<
SherpaOnnxOnlinePunctuation
>);
typedef
SherpaOnnxOnlinePunctuationAddPunctNative
=
Pointer
<
Utf8
>
Function
(
Pointer
<
SherpaOnnxOnlinePunctuation
>,
Pointer
<
Utf8
>);
typedef
SherpaOnnxOnlinePunctuationAddPunct
=
SherpaOnnxOnlinePunctuationAddPunctNative
;
typedef
SherpaOnnxOnlinePunctuationFreeTextNative
=
Void
Function
(
Pointer
<
Utf8
>);
typedef
SherpaOnnxOnlinePunctuationFreeText
=
void
Function
(
Pointer
<
Utf8
>);
typedef
SherpaOnnxCreateAudioTaggingNative
=
Pointer
<
SherpaOnnxAudioTagging
>
Function
(
Pointer
<
SherpaOnnxAudioTaggingConfig
>);
...
...
@@ -1155,6 +1195,13 @@ class SherpaOnnxBindings {
static
SherpaOfflinePunctuationAddPunct
?
sherpaOfflinePunctuationAddPunct
;
static
SherpaOfflinePunctuationFreeText
?
sherpaOfflinePunctuationFreeText
;
static
SherpaOnnxCreateOnlinePunctuation
?
sherpaOnnxCreateOnlinePunctuation
;
static
SherpaOnnxDestroyOnlinePunctuation
?
sherpaOnnxDestroyOnlinePunctuation
;
static
SherpaOnnxOnlinePunctuationAddPunct
?
sherpaOnnxOnlinePunctuationAddPunct
;
static
SherpaOnnxOnlinePunctuationFreeText
?
sherpaOnnxOnlinePunctuationFreeText
;
static
SherpaOnnxCreateAudioTagging
?
sherpaOnnxCreateAudioTagging
;
static
SherpaOnnxDestroyAudioTagging
?
sherpaOnnxDestroyAudioTagging
;
static
SherpaOnnxAudioTaggingCreateOfflineStream
?
...
...
@@ -1414,6 +1461,26 @@ class SherpaOnnxBindings {
'SherpaOfflinePunctuationFreeText'
)
.
asFunction
();
sherpaOnnxCreateOnlinePunctuation
??=
dynamicLibrary
.
lookup
<
NativeFunction
<
SherpaOnnxCreateOnlinePunctuationNative
>>(
'SherpaOnnxCreateOnlinePunctuation'
)
.
asFunction
();
sherpaOnnxDestroyOnlinePunctuation
??=
dynamicLibrary
.
lookup
<
NativeFunction
<
SherpaOnnxDestroyOnlinePunctuationNative
>>(
'SherpaOnnxDestroyOnlinePunctuation'
)
.
asFunction
();
sherpaOnnxOnlinePunctuationAddPunct
??=
dynamicLibrary
.
lookup
<
NativeFunction
<
SherpaOnnxOnlinePunctuationAddPunctNative
>>(
'SherpaOnnxOnlinePunctuationAddPunct'
)
.
asFunction
();
sherpaOnnxOnlinePunctuationFreeText
??=
dynamicLibrary
.
lookup
<
NativeFunction
<
SherpaOnnxOnlinePunctuationFreeTextNative
>>(
'SherpaOnnxOnlinePunctuationFreeText'
)
.
asFunction
();
sherpaOnnxCreateAudioTagging
??=
dynamicLibrary
.
lookup
<
NativeFunction
<
SherpaOnnxCreateAudioTaggingNative
>>(
'SherpaOnnxCreateAudioTagging'
)
...
...
请
注册
或
登录
后发表评论