fix: probe loads model before recording and shows signal levels
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,11 +2,29 @@ import Foundation
|
|||||||
import SstWhisper
|
import SstWhisper
|
||||||
|
|
||||||
func runTranscribeProbe() async {
|
func runTranscribeProbe() async {
|
||||||
guard let samples = await recordSamples(seconds: 6) else { return }
|
|
||||||
print("Model laden (eerste keer: download ≈1.5 GB)…")
|
print("Model laden (eerste keer: download ≈1.5 GB)…")
|
||||||
let transcriber = WhisperKitTranscriber()
|
let transcriber = WhisperKitTranscriber()
|
||||||
do {
|
do {
|
||||||
try await transcriber.load()
|
try await transcriber.load()
|
||||||
|
} catch {
|
||||||
|
print("mislukt:", error.localizedDescription)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
print("Model klaar.")
|
||||||
|
for i in [3, 2, 1] {
|
||||||
|
print("\(i)...")
|
||||||
|
try? await Task.sleep(for: .seconds(1))
|
||||||
|
}
|
||||||
|
guard let samples = await recordSamples(seconds: 8) else { return }
|
||||||
|
let peak = samples.map { abs($0) }.max() ?? 0
|
||||||
|
print("samples: \(samples.count), piek: \(peak)")
|
||||||
|
let perSecond = stride(from: 0, to: samples.count, by: 16_000).map { start -> String in
|
||||||
|
let chunk = samples[start..<min(start + 16_000, samples.count)]
|
||||||
|
let rms = (chunk.reduce(0) { $0 + $1 * $1 } / Float(chunk.count)).squareRoot()
|
||||||
|
return String(format: "%.3f", rms)
|
||||||
|
}
|
||||||
|
print("RMS per seconde:", perSecond.joined(separator: " "))
|
||||||
|
do {
|
||||||
let started = Date.now
|
let started = Date.now
|
||||||
let text = try await transcriber.transcribe(samples)
|
let text = try await transcriber.transcribe(samples)
|
||||||
let elapsed = Date.now.timeIntervalSince(started)
|
let elapsed = Date.now.timeIntervalSince(started)
|
||||||
|
|||||||
Reference in New Issue
Block a user