uttrflow / uttrflow/uttrflow-swift
AudioResampler passes NaN and infinite samples through, and spreads them to neighbouring samples
- Dominant language
- Swift
- Stars
- 4
- Forks
- 17
- Avg merge
- 3h 32m
- Merged PRs (30d)
- 277
Description
## What happens
`AudioResampler.resample` (`Sources/UttrflowAudio/AudioResampler.swift:41-58`) hands buffers to `AVAudioConverter` and returns whatever comes back (line 84). Nothing sanitises the samples, and the converter's filter smears a bad sample over its neighbours. Feeding one 960-frame 48 kHz buffer of `0.1` with a single NaN and a single `+infinity` into the same conversion produced 314 output samples with 11 NaN and 10 infinite values. At 16 kHz in, the NaN and infinity came straight through.
Nothing downstream on the dictation path checks either: `SampleAccumulator` ignores them for the level meter only, and stores them with the recording.
## Why it matters
Non-finite samples reach the recogniser and the saved recording. A single bad value from a device or driver can turn a whole stretch of audio into noise for the model.
## How to check
Extend `Tests/UttrflowAudioTests/AudioResamplerTests.swift`: build a 48 kHz mono buffer with one `.nan` and one `.infinity`, resample it, and count non-finite values in the result. Today the count is well above zero.
## Acceptance criteria
- `resample` never returns a NaN or infinite sample. Replace non-finite input samples with 0 before conversion (and clamp output to `-1...1` or check it again afterwards, whichever you can justify in a one-line comment).
- Tests cover canonical-rate input (16 kHz) and downsampled input (48 kHz), with NaN, `+infinity` and `-infinity`.
- The existing test "passes canonical-format audio through unchanged" still passes for ordinary audio.
## Where to start
- `Sources/UttrflowAudio/AudioResampler.swift`
- Tests to extend: `Tests/UttrflowAudioTests/AudioResamplerTests.swift`.
- Before pushing, run `make verify` (export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer first). It is the same command CI runs, and it enforces the 95% coverage floor per module.
- Read [CONTRIBUTING.md](https://github.com/uttrflow/uttrflow-swift/blob/main/CONTRIBUTING.md) first, and say on this issue that you are taking it.
**Size:** S to M, about 2-4 hours.
Contributor guide
Research direction
Read CONTRIBUTING.md first, then inspect Sources/UttrflowAudio/AudioResampler.swift, especially resample and its AVAudioConverter path. Extend Tests/UttrflowAudioTests/AudioResamplerTests.swift for 16 kHz and 48 kHz input containing NaN and both infinities, while preserving the ordinary pass-through test. Run make verify with DEVELOPER_DIR set; done means no non-finite output and the existing suite and coverage checks pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- audio-video-rtc
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 86/100