Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
sherpaonnx
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Fangjun Kuang
2024-10-27 08:19:01 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-10-27 08:19:01 +0800
Commit
4a4659aa4fad632280abdf6e5ae9f7896cb75d09
4a4659aa
1 parent
2ca2985d
Add Swift API for Moonshine models. (#1477)
隐藏空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
39 行增加
和
2 行删除
swift-api-examples/SherpaOnnx.swift
swift-api-examples/decode-file-non-streaming.swift
swift-api-examples/SherpaOnnx.swift
查看文件 @
4a4659a
...
...
@@ -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
{
...
...
@@ -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
,
...
...
@@ -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
)
}
...
...
swift-api-examples/decode-file-non-streaming.swift
查看文件 @
4a4659a
...
...
@@ -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"
...
...
@@ -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
...
...
@@ -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
)
...
...
请
注册
或
登录
后发表评论