This commit is contained in:
James Babcock committed 2026-11-12 12:20:29 -08:00
commit c162c8e633
24 files changed
+486 -154

No files matched your search

@@ -136,8 +136,6 @@ class FaceclawVoiceController(context: Context) {
override fun release() {}
}
}
override fun recordingSink(): RecordingSink = RecordingSink { pcmBytes, sampleRate -> saveRecording(pcmBytes, sampleRate) }
}
private val session = VoiceCaptureSession(host)
@@ -155,11 +153,6 @@ class FaceclawVoiceController(context: Context) {
session.setUsePhoneMic(usePhoneMic)
}
/** When true, the decoded mic PCM for each session is saved as a WAV. */
fun setSaveRecordings(saveRecordings: Boolean) {
session.setSaveRecordings(saveRecordings)
}
/**
* Which on-device model {@link #start}("onboard") should load: "whisper"
* selects the second on-device model (sherpa-onnx offline Whisper); any
@@ -233,29 +226,6 @@ class FaceclawVoiceController(context: Context) {
stop()
}
/** Save the session's decoded mic PCM as a 16 kHz mono 16-bit WAV. */
private fun saveRecording(pcmBytes: ByteArray, sampleRate: Int) {
try {
val dir = File(appContext.getExternalFilesDir(null), "voice-recordings")
if (!dir.exists() && !dir.mkdirs()) {
Log.w(TAG, "could not create voice-recordings dir")
return
}
val stamp = java.text.SimpleDateFormat("yyyyMMdd-HHmmss-SSS", java.util.Locale.US)
.format(java.util.Date())
val file = File(dir, "voice-$stamp.wav")
java.io.FileOutputStream(file).use { fos ->
fos.write(BinaryEncoding.wavHeader(pcmBytes.size, sampleRate, 1))
fos.write(pcmBytes)
}
Log.i(TAG, "saved voice recording " + file.absolutePath
+ " samples=" + (pcmBytes.size / 2)
+ " sec=" + String.format(java.util.Locale.US, "%.2f", pcmBytes.size / 2.0 / sampleRate))
} catch (t: Throwable) {
Log.w(TAG, "failed to save voice recording", t)
}
}
/**
* The on-device model directory for the given kind, populated by the
* download flow in asr-model.ts (releases before 0.5.0 copied the