-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathcohere-transcribe.swift
More file actions
53 lines (43 loc) · 1.37 KB
/
cohere-transcribe.swift
File metadata and controls
53 lines (43 loc) · 1.37 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
46
47
48
49
50
51
52
53
func run() {
let encoder =
"./sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01/encoder.int8.onnx"
let decoder =
"./sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01/decoder.int8.onnx"
let tokens =
"./sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01/tokens.txt"
let cohereTranscribe = sherpaOnnxOfflineCohereTranscribeModelConfig(
encoder: encoder,
decoder: decoder,
usePunct: true,
useInverseTextNormalization: true
)
let modelConfig = sherpaOnnxOfflineModelConfig(
tokens: tokens,
numThreads: 1,
provider: "cpu",
debug: 0,
cohereTranscribe: cohereTranscribe
)
let featConfig = sherpaOnnxFeatureConfig()
var config = sherpaOnnxOfflineRecognizerConfig(
featConfig: featConfig,
modelConfig: modelConfig
)
let recognizer = SherpaOnnxOfflineRecognizer(config: &config)
let filePath =
"./sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01/test_wavs/en.wav"
let audio = SherpaOnnxWaveWrapper.readWave(filename: filePath)
let stream = recognizer.createStream()
stream.setOption(key: "language", value: "en")
stream.acceptWaveform(samples: audio.samples, sampleRate: audio.sampleRate)
recognizer.decode(stream: stream)
let result = recognizer.getResult(stream: stream)
print("decode done")
print("\nresult is:\n\(result.text)")
}
@main
struct App {
static func main() {
run()
}
}