MCPcopy Create free account
hub / github.com/freecodexyz/free-code / startArecordRecording

Function startArecordRecording

src/services/voice.ts:496–541  ·  view source on GitHub ↗
(
  onData: (chunk: Buffer) => void,
  onEnd: () => void,
)

Source from the content-addressed store, hash-verified

494}
495
496function startArecordRecording(
497 onData: (chunk: Buffer) => void,
498 onEnd: () => void,
499): boolean {
500 // Record raw PCM: 16 kHz, 16-bit signed little-endian, mono, to stdout.
501 // arecord does not support built-in silence detection, so this backend
502 // is best suited for push-to-talk (silenceDetection: false).
503 const args = [
504 '-f',
505 'S16_LE', // signed 16-bit little-endian
506 '-r',
507 String(RECORDING_SAMPLE_RATE),
508 '-c',
509 String(RECORDING_CHANNELS),
510 '-t',
511 'raw', // raw PCM, no WAV header
512 '-q', // quiet — no progress output
513 '-', // write to stdout
514 ]
515
516 const child = spawn('arecord', args, {
517 stdio: ['pipe', 'pipe', 'pipe'],
518 })
519
520 activeRecorder = child
521
522 child.stdout?.on('data', (chunk: Buffer) => {
523 onData(chunk)
524 })
525
526 // Consume stderr to prevent backpressure
527 child.stderr?.on('data', () => {})
528
529 child.on('close', () => {
530 activeRecorder = null
531 onEnd()
532 })
533
534 child.on('error', err => {
535 logError(err)
536 activeRecorder = null
537 onEnd()
538 })
539
540 return true
541}
542
543export function stopRecording(): void {
544 if (nativeRecordingActive && audioNapi) {

Callers 1

startRecordingFunction · 0.85

Calls 4

spawnFunction · 0.85
onEndFunction · 0.85
onDataFunction · 0.50
logErrorFunction · 0.50

Tested by

no test coverage detected