Add swift online punctuation (#1661)

This commit is contained in:
yujinqiu
2024-12-31 11:26:32 +08:00
committed by GitHub
parent 49154c957b
commit 5c2cc48f50
5 changed files with 198 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
func run() {
let model = "./sherpa-onnx-online-punct-en-2024-08-06/model.onnx"
let bpe = "./sherpa-onnx-online-punct-en-2024-08-06/bpe.vocab"
// Create model config
let modelConfig = sherpaOnnxOnlinePunctuationModelConfig(
cnnBiLstm: model,
bpeVocab: bpe
)
// Create punctuation config
var config = sherpaOnnxOnlinePunctuationConfig(model: modelConfig)
// Create punctuation instance
let punct = SherpaOnnxOnlinePunctuationWrapper(config: &config)
// Test texts
let textList = [
"how are you i am fine thank you",
"The African blogosphere is rapidly expanding bringing more voices online in the form of commentaries opinions analyses rants and poetry"
]
// Process each text
for i in 0..<textList.count {
let t = punct.addPunct(text: textList[i])
print("\nresult is:\n\(t)")
}
}
@main
struct App {
static func main() {
run()
}
}