feat: add AudioRecorder (16 kHz mono) and record probe
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import AVFoundation
|
||||
import SstCore
|
||||
|
||||
/// Records `seconds` of microphone audio; returns nil if access is denied or recording fails.
|
||||
func recordSamples(seconds: Double) async -> [Float]? {
|
||||
guard await AVCaptureDevice.requestAccess(for: .audio) else {
|
||||
print("Microfoon-toegang geweigerd (Systeeminstellingen → Privacy → Microfoon).")
|
||||
return nil
|
||||
}
|
||||
let recorder = AudioRecorder()
|
||||
do { try recorder.start() } catch {
|
||||
print("start mislukt:", error.localizedDescription)
|
||||
return nil
|
||||
}
|
||||
print("Neem \(Int(seconds)) s op — praat nu")
|
||||
try? await Task.sleep(for: .seconds(seconds))
|
||||
return recorder.stop()
|
||||
}
|
||||
|
||||
func runRecordProbe() async {
|
||||
guard let samples = await recordSamples(seconds: 3) else { return }
|
||||
let peak = samples.map { abs($0) }.max() ?? 0
|
||||
print("samples: \(samples.count) (verwacht ≈ 48000), piek: \(peak)")
|
||||
}
|
||||
@@ -4,6 +4,8 @@ let command = CommandLine.arguments.dropFirst().first ?? "help"
|
||||
switch command {
|
||||
case "hotkey":
|
||||
runHotkeyProbe()
|
||||
case "record":
|
||||
await runRecordProbe()
|
||||
default:
|
||||
print("usage: sst-probe hotkey")
|
||||
print("usage: sst-probe hotkey|record")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user