Add Swift API for adding punctuations to text. (#1132)

This commit is contained in:
Fangjun Kuang
2024-07-15 15:30:40 +08:00
committed by GitHub
parent 11cfd33b10
commit b2c283fa2b
5 changed files with 119 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
func run() {
let model = "./sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12/model.onnx"
let modelConfig = sherpaOnnxOfflinePunctuationModelConfig(
ctTransformer: model,
numThreads: 1,
debug: 1,
provider: "cpu"
)
var config = sherpaOnnxOfflinePunctuationConfig(model: modelConfig)
let punct = SherpaOnnxOfflinePunctuationWrapper(config: &config)
let textList = [
"这是一个测试你好吗How are you我很好thank you are you ok谢谢你",
"我们都是木头人不会说话不会动",
"The African blogosphere is rapidly expanding bringing more voices online in the form of commentaries opinions analyses rants and poetry",
]
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()
}
}