Committed by
GitHub
Add Swift API for Moonshine models. (#1477)
正在显示
2 个修改的文件
包含
39 行增加
和
2 行删除
| @@ -357,6 +357,20 @@ func sherpaOnnxOfflineWhisperModelConfig( | @@ -357,6 +357,20 @@ func sherpaOnnxOfflineWhisperModelConfig( | ||
| 357 | ) | 357 | ) |
| 358 | } | 358 | } |
| 359 | 359 | ||
| 360 | +func sherpaOnnxOfflineMoonshineModelConfig( | ||
| 361 | + preprocessor: String = "", | ||
| 362 | + encoder: String = "", | ||
| 363 | + uncachedDecoder: String = "", | ||
| 364 | + cachedDecoder: String = "" | ||
| 365 | +) -> SherpaOnnxOfflineMoonshineModelConfig { | ||
| 366 | + return SherpaOnnxOfflineMoonshineModelConfig( | ||
| 367 | + preprocessor: toCPointer(preprocessor), | ||
| 368 | + encoder: toCPointer(encoder), | ||
| 369 | + uncached_decoder: toCPointer(uncachedDecoder), | ||
| 370 | + cached_decoder: toCPointer(cachedDecoder) | ||
| 371 | + ) | ||
| 372 | +} | ||
| 373 | + | ||
| 360 | func sherpaOnnxOfflineTdnnModelConfig( | 374 | func sherpaOnnxOfflineTdnnModelConfig( |
| 361 | model: String = "" | 375 | model: String = "" |
| 362 | ) -> SherpaOnnxOfflineTdnnModelConfig { | 376 | ) -> SherpaOnnxOfflineTdnnModelConfig { |
| @@ -401,7 +415,8 @@ func sherpaOnnxOfflineModelConfig( | @@ -401,7 +415,8 @@ func sherpaOnnxOfflineModelConfig( | ||
| 401 | modelingUnit: String = "cjkchar", | 415 | modelingUnit: String = "cjkchar", |
| 402 | bpeVocab: String = "", | 416 | bpeVocab: String = "", |
| 403 | teleSpeechCtc: String = "", | 417 | teleSpeechCtc: String = "", |
| 404 | - senseVoice: SherpaOnnxOfflineSenseVoiceModelConfig = sherpaOnnxOfflineSenseVoiceModelConfig() | 418 | + senseVoice: SherpaOnnxOfflineSenseVoiceModelConfig = sherpaOnnxOfflineSenseVoiceModelConfig(), |
| 419 | + moonshine: SherpaOnnxOfflineMoonshineModelConfig = sherpaOnnxOfflineMoonshineModelConfig() | ||
| 405 | ) -> SherpaOnnxOfflineModelConfig { | 420 | ) -> SherpaOnnxOfflineModelConfig { |
| 406 | return SherpaOnnxOfflineModelConfig( | 421 | return SherpaOnnxOfflineModelConfig( |
| 407 | transducer: transducer, | 422 | transducer: transducer, |
| @@ -417,7 +432,8 @@ func sherpaOnnxOfflineModelConfig( | @@ -417,7 +432,8 @@ func sherpaOnnxOfflineModelConfig( | ||
| 417 | modeling_unit: toCPointer(modelingUnit), | 432 | modeling_unit: toCPointer(modelingUnit), |
| 418 | bpe_vocab: toCPointer(bpeVocab), | 433 | bpe_vocab: toCPointer(bpeVocab), |
| 419 | telespeech_ctc: toCPointer(teleSpeechCtc), | 434 | telespeech_ctc: toCPointer(teleSpeechCtc), |
| 420 | - sense_voice: senseVoice | 435 | + sense_voice: senseVoice, |
| 436 | + moonshine: moonshine | ||
| 421 | ) | 437 | ) |
| 422 | } | 438 | } |
| 423 | 439 |
| @@ -18,6 +18,7 @@ func run() { | @@ -18,6 +18,7 @@ func run() { | ||
| 18 | var modelType = "whisper" | 18 | var modelType = "whisper" |
| 19 | // modelType = "paraformer" | 19 | // modelType = "paraformer" |
| 20 | // modelType = "sense_voice" | 20 | // modelType = "sense_voice" |
| 21 | + // modelType = "moonshine" | ||
| 21 | 22 | ||
| 22 | if modelType == "whisper" { | 23 | if modelType == "whisper" { |
| 23 | let encoder = "./sherpa-onnx-whisper-tiny.en/tiny.en-encoder.int8.onnx" | 24 | let encoder = "./sherpa-onnx-whisper-tiny.en/tiny.en-encoder.int8.onnx" |
| @@ -61,6 +62,24 @@ func run() { | @@ -61,6 +62,24 @@ func run() { | ||
| 61 | debug: 0, | 62 | debug: 0, |
| 62 | senseVoice: senseVoiceConfig | 63 | senseVoice: senseVoiceConfig |
| 63 | ) | 64 | ) |
| 65 | + } else if modelType == "moonshine" { | ||
| 66 | + let preprocessor = "./sherpa-onnx-moonshine-tiny-en-int8/preprocess.onnx" | ||
| 67 | + let encoder = "./sherpa-onnx-moonshine-tiny-en-int8/encode.int8.onnx" | ||
| 68 | + let uncachedDecoder = "./sherpa-onnx-moonshine-tiny-en-int8/uncached_decode.int8.onnx" | ||
| 69 | + let cachedDecoder = "./sherpa-onnx-moonshine-tiny-en-int8/cached_decode.int8.onnx" | ||
| 70 | + let tokens = "./sherpa-onnx-moonshine-tiny-en-int8/tokens.txt" | ||
| 71 | + let moonshine = sherpaOnnxOfflineMoonshineModelConfig( | ||
| 72 | + preprocessor: preprocessor, | ||
| 73 | + encoder: encoder, | ||
| 74 | + uncachedDecoder: uncachedDecoder, | ||
| 75 | + cachedDecoder: cachedDecoder | ||
| 76 | + ) | ||
| 77 | + | ||
| 78 | + modelConfig = sherpaOnnxOfflineModelConfig( | ||
| 79 | + tokens: tokens, | ||
| 80 | + debug: 0, | ||
| 81 | + moonshine: moonshine | ||
| 82 | + ) | ||
| 64 | } else { | 83 | } else { |
| 65 | print("Please specify a supported modelType \(modelType)") | 84 | print("Please specify a supported modelType \(modelType)") |
| 66 | return | 85 | return |
| @@ -80,6 +99,8 @@ func run() { | @@ -80,6 +99,8 @@ func run() { | ||
| 80 | var filePath = "./sherpa-onnx-whisper-tiny.en/test_wavs/0.wav" | 99 | var filePath = "./sherpa-onnx-whisper-tiny.en/test_wavs/0.wav" |
| 81 | if modelType == "sense_voice" { | 100 | if modelType == "sense_voice" { |
| 82 | filePath = "./sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17/test_wavs/zh.wav" | 101 | filePath = "./sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17/test_wavs/zh.wav" |
| 102 | + } else if modelType == "moonshine" { | ||
| 103 | + filePath = "./sherpa-onnx-moonshine-tiny-en-int8/test_wavs/0.wav" | ||
| 83 | } | 104 | } |
| 84 | let fileURL: NSURL = NSURL(fileURLWithPath: filePath) | 105 | let fileURL: NSURL = NSURL(fileURLWithPath: filePath) |
| 85 | let audioFile = try! AVAudioFile(forReading: fileURL as URL) | 106 | let audioFile = try! AVAudioFile(forReading: fileURL as URL) |
-
请 注册 或 登录 后发表评论