-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add swift online punctuation (#1661)
- Loading branch information
Showing
5 changed files
with
198 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
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,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() | ||
} | ||
} |
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,36 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
if [ ! -d ../build-swift-macos ]; then | ||
echo "Please run ../build-swift-macos.sh first!" | ||
exit 1 | ||
fi | ||
|
||
# Download and extract the online punctuation model if not exists | ||
if [ ! -d ./sherpa-onnx-online-punct-en-2024-08-06 ]; then | ||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/punctuation-models/sherpa-onnx-online-punct-en-2024-08-06.tar.bz2 | ||
tar xvf sherpa-onnx-online-punct-en-2024-08-06.tar.bz2 | ||
rm sherpa-onnx-online-punct-en-2024-08-06.tar.bz2 | ||
fi | ||
|
||
if [ ! -e ./add-punctuation-online ]; 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-punctuation-online.swift ./SherpaOnnx.swift \ | ||
-L ../build-swift-macos/install/lib/ \ | ||
-l sherpa-onnx \ | ||
-l onnxruntime \ | ||
-o ./add-punctuation-online | ||
|
||
strip ./add-punctuation-online | ||
else | ||
echo "./add-punctuation-online exists - skip building" | ||
fi | ||
|
||
# Set library path and run the executable | ||
export DYLD_LIBRARY_PATH=$PWD/../build-swift-macos/install/lib:$DYLD_LIBRARY_PATH | ||
./add-punctuation-online |