( onData: (chunk: Buffer) => void, onEnd: () => void, )
| 494 | } |
| 495 | |
| 496 | function 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 | |
| 543 | export function stopRecording(): void { |
| 544 | if (nativeRecordingActive && audioNapi) { |
no test coverage detected