Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Swift API for Moonshine models. #1477

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions swift-api-examples/SherpaOnnx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,20 @@ func sherpaOnnxOfflineWhisperModelConfig(
)
}

func sherpaOnnxOfflineMoonshineModelConfig(
preprocessor: String = "",
encoder: String = "",
uncachedDecoder: String = "",
cachedDecoder: String = ""
) -> SherpaOnnxOfflineMoonshineModelConfig {
return SherpaOnnxOfflineMoonshineModelConfig(
preprocessor: toCPointer(preprocessor),
encoder: toCPointer(encoder),
uncached_decoder: toCPointer(uncachedDecoder),
cached_decoder: toCPointer(cachedDecoder)
)
}

func sherpaOnnxOfflineTdnnModelConfig(
model: String = ""
) -> SherpaOnnxOfflineTdnnModelConfig {
Expand Down Expand Up @@ -401,7 +415,8 @@ func sherpaOnnxOfflineModelConfig(
modelingUnit: String = "cjkchar",
bpeVocab: String = "",
teleSpeechCtc: String = "",
senseVoice: SherpaOnnxOfflineSenseVoiceModelConfig = sherpaOnnxOfflineSenseVoiceModelConfig()
senseVoice: SherpaOnnxOfflineSenseVoiceModelConfig = sherpaOnnxOfflineSenseVoiceModelConfig(),
moonshine: SherpaOnnxOfflineMoonshineModelConfig = sherpaOnnxOfflineMoonshineModelConfig()
) -> SherpaOnnxOfflineModelConfig {
return SherpaOnnxOfflineModelConfig(
transducer: transducer,
Expand All @@ -417,7 +432,8 @@ func sherpaOnnxOfflineModelConfig(
modeling_unit: toCPointer(modelingUnit),
bpe_vocab: toCPointer(bpeVocab),
telespeech_ctc: toCPointer(teleSpeechCtc),
sense_voice: senseVoice
sense_voice: senseVoice,
moonshine: moonshine
)
}

Expand Down
21 changes: 21 additions & 0 deletions swift-api-examples/decode-file-non-streaming.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func run() {
var modelType = "whisper"
// modelType = "paraformer"
// modelType = "sense_voice"
// modelType = "moonshine"

if modelType == "whisper" {
let encoder = "./sherpa-onnx-whisper-tiny.en/tiny.en-encoder.int8.onnx"
Expand Down Expand Up @@ -61,6 +62,24 @@ func run() {
debug: 0,
senseVoice: senseVoiceConfig
)
} else if modelType == "moonshine" {
let preprocessor = "./sherpa-onnx-moonshine-tiny-en-int8/preprocess.onnx"
let encoder = "./sherpa-onnx-moonshine-tiny-en-int8/encode.int8.onnx"
let uncachedDecoder = "./sherpa-onnx-moonshine-tiny-en-int8/uncached_decode.int8.onnx"
let cachedDecoder = "./sherpa-onnx-moonshine-tiny-en-int8/cached_decode.int8.onnx"
let tokens = "./sherpa-onnx-moonshine-tiny-en-int8/tokens.txt"
let moonshine = sherpaOnnxOfflineMoonshineModelConfig(
preprocessor: preprocessor,
encoder: encoder,
uncachedDecoder: uncachedDecoder,
cachedDecoder: cachedDecoder
)

modelConfig = sherpaOnnxOfflineModelConfig(
tokens: tokens,
debug: 0,
moonshine: moonshine
)
} else {
print("Please specify a supported modelType \(modelType)")
return
Expand All @@ -80,6 +99,8 @@ func run() {
var filePath = "./sherpa-onnx-whisper-tiny.en/test_wavs/0.wav"
if modelType == "sense_voice" {
filePath = "./sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17/test_wavs/zh.wav"
} else if modelType == "moonshine" {
filePath = "./sherpa-onnx-moonshine-tiny-en-int8/test_wavs/0.wav"
}
let fileURL: NSURL = NSURL(fileURLWithPath: filePath)
let audioFile = try! AVAudioFile(forReading: fileURL as URL)
Expand Down