Add Swift API for adding punctuations to text. (#1132)
This commit is contained in:
@@ -957,3 +957,52 @@ class SherpaOnnxKeywordSpotterWrapper {
|
||||
InputFinished(stream)
|
||||
}
|
||||
}
|
||||
|
||||
// Punctuation
|
||||
|
||||
func sherpaOnnxOfflinePunctuationModelConfig(
|
||||
ctTransformer: String,
|
||||
numThreads: Int = 1,
|
||||
debug: Int = 0,
|
||||
provider: String = "cpu"
|
||||
) -> SherpaOnnxOfflinePunctuationModelConfig {
|
||||
return SherpaOnnxOfflinePunctuationModelConfig(
|
||||
ct_transformer: toCPointer(ctTransformer),
|
||||
num_threads: Int32(numThreads),
|
||||
debug: Int32(debug),
|
||||
provider: toCPointer(provider)
|
||||
)
|
||||
}
|
||||
|
||||
func sherpaOnnxOfflinePunctuationConfig(
|
||||
model: SherpaOnnxOfflinePunctuationModelConfig
|
||||
) -> SherpaOnnxOfflinePunctuationConfig {
|
||||
return SherpaOnnxOfflinePunctuationConfig(
|
||||
model: model
|
||||
)
|
||||
}
|
||||
|
||||
class SherpaOnnxOfflinePunctuationWrapper {
|
||||
/// A pointer to the underlying counterpart in C
|
||||
let ptr: OpaquePointer!
|
||||
|
||||
/// Constructor taking a model config
|
||||
init(
|
||||
config: UnsafePointer<SherpaOnnxOfflinePunctuationConfig>!
|
||||
) {
|
||||
ptr = SherpaOnnxCreateOfflinePunctuation(config)
|
||||
}
|
||||
|
||||
deinit {
|
||||
if let ptr {
|
||||
SherpaOnnxDestroyOfflinePunctuation(ptr)
|
||||
}
|
||||
}
|
||||
|
||||
func addPunct(text: String) -> String {
|
||||
let cText = SherpaOfflinePunctuationAddPunct(ptr, toCPointer(text))
|
||||
let ans = String(cString: cText!)
|
||||
SherpaOfflinePunctuationFreeText(cText)
|
||||
return ans
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user