Repository navigation
fix(stt): capture through parec instead of sox -t pulseaudio on Linux - #27
Open
fede-ciliberti wants to merge 1 commit into
Open
fede-ciliberti wants to merge 1 commit into
fede-ciliberti wants to merge 1 commit into
Conversation
detectAudioBackend() assumed that a reachable PulseAudio server implies sox can open a pulseaudio source. Stock Debian/Ubuntu sox ships only libsox-fmt-alsa and libsox-fmt-base, so recording died with: Recording error: sox FAIL formats: no handler for given file type `pulseaudio' Capture now goes through parec (pulseaudio-utils, present wherever pactl is) and its stdout is piped into sox as raw PCM, which needs no sox format plugin. The sox pulseaudio path stays for systems that do have the handler; parec is only preferred when the binary exists, and the coreaudio/alsa paths are untouched. Stopping waits a 500ms grace period before SIGINT so the server-side buffer drains into the pipe instead of discarding the tail of the speech, and waitForSoxExit gets a longer budget for the pipe to flush.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
On Linux, recording fails on any distro whose
soxwas built without thePulseAudio format handler:
detectAudioBackend()returnspulseaudiowheneverpactlanswers, andbuildRecordArgs()then asks sox for-t pulseaudio. Debian and Ubuntu shipsoxwith onlylibsox-fmt-alsaandlibsox-fmt-baseunless the optionallibsox-fmt-pulsepackage is installed, so the capture dies before recordinganything.
This captures through
parecinstead (part ofpulseaudio-utils, presentwherever
pactlis) and pipes its stdout into sox as raw PCM, which needs nosox format plugin:
The
sox -t pulseaudiopath is kept for systems that do have the handler;parecis only preferred when the binary exists.coreaudioand the plainsox -dpaths are untouched.Also
Stopping waits a 500ms grace period before
SIGINTto parec: PulseAudio keepsthe captured audio in a server-side buffer and killing the process immediately
discards the tail of the speech (measured ~0.5-0.8s on a PipeWire system).
waitForSoxExitgets a longer budget so the pipe can flush.Verification
mono WAV through
parec | soxpulseaudiobranch is now only taken whenparecis absent andsox --helpreports pulseaudio supportisPulseLikeBackend()and the hints for theparecbackendnpm test22/22,npx oxlint .clean,npx oxfmt --check .clean