-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Swift API for adding punctuations to text. (#1132)
- Loading branch information
1 parent
11cfd33
commit b2c283f
Showing
5 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ sherpa-onnx-paraformer-zh-2023-09-14 | |
*.bak | ||
streaming-hlg-decode-file | ||
keyword-spotting-from-file | ||
add-punctuations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
if [ ! -d ../build-swift-macos ]; then | ||
echo "Please run ../build-swift-macos.sh first!" | ||
exit 1 | ||
fi | ||
|
||
if [ ! -d ./sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12 ]; then | ||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/punctuation-models/sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12.tar.bz2 | ||
tar xvf sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12.tar.bz2 | ||
rm sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12.tar.bz2 | ||
fi | ||
|
||
if [ ! -e ./add-punctuations ]; then | ||
# Note: We use -lc++ to link against libc++ instead of libstdc++ | ||
swiftc \ | ||
-lc++ \ | ||
-I ../build-swift-macos/install/include \ | ||
-import-objc-header ./SherpaOnnx-Bridging-Header.h \ | ||
./add-punctuations.swift ./SherpaOnnx.swift \ | ||
-L ../build-swift-macos/install/lib/ \ | ||
-l sherpa-onnx \ | ||
-l onnxruntime \ | ||
-o ./add-punctuations | ||
|
||
strip ./add-punctuations | ||
else | ||
echo "./add-punctuations exists - skip building" | ||
fi | ||
|
||
export DYLD_LIBRARY_PATH=$PWD/../build-swift-macos/install/lib:$DYLD_LIBRARY_PATH | ||
./add-punctuations |