-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathmoonshine-v2-asr.swift
More file actions
45 lines (37 loc) · 1.17 KB
/
moonshine-v2-asr.swift
File metadata and controls
45 lines (37 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
func run() {
let encoder =
"./sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27/encoder_model.ort"
let decoder =
"./sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27/decoder_model_merged.ort"
let tokens =
"./sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27/tokens.txt"
let moonshine = sherpaOnnxOfflineMoonshineModelConfig(
encoder: encoder,
mergedDecoder: decoder
)
let modelConfig = sherpaOnnxOfflineModelConfig(
tokens: tokens,
debug: 1,
moonshine: moonshine
)
let featConfig = sherpaOnnxFeatureConfig()
var config = sherpaOnnxOfflineRecognizerConfig(
featConfig: featConfig,
modelConfig: modelConfig
)
let recognizer = SherpaOnnxOfflineRecognizer(config: &config)
let filePath = "./sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27/test_wavs/0.wav"
let audio = SherpaOnnxWaveWrapper.readWave(filename: filePath)
let result = recognizer.decode(samples: audio.samples, sampleRate: audio.sampleRate)
print("decode done")
print("\nresult is:\n\(result.text)")
if result.timestamps.count != 0 {
print("\ntimestamps is:\n\(result.timestamps)")
}
}
@main
struct App {
static func main() {
run()
}
}