whisper icon indicating copy to clipboard operation
whisper copied to clipboard

Support for Buffered Audio Data

Open kentslaney opened this issue 7 months ago • 2 comments

This pull request adds the CLI flag --buffered, which allows the audio data to be loaded on-demand through an I/O buffer instead of all at once at the beginning. This provides an alternative resolution to the problem addressed in #2256. The default memory limit is dictated here, but shouldn't matter much since it's not a bottleneck.

Support for buffered input also paves the way towards real-time tasks (#2): the changes were directly adapted from kentslaney/realtime-whisper, which already supports live PCM data. In order to keep the PR from being any larger than it already is, changes were limited to the minimum motivating feature. I'm making a PR instead of keeping it as a wrapper because it reuses/refactors large chunks of transcribe, which the current scoping makes inaccessible for patching.

The buffered version will perform almost exactly the same set of operations, with a small (vanishing) difference in the preprocessing output. The log mel spectogram is clamped below to have a maximum range of 8. The original transcribe method computes the upper bound from the entire file's spectogram, while the buffered version clamps the values relative to the maximum in the chunks processed so far. I have done some regression testing to confirm that the refactored (non-buffered) solution will make the same calls as the existing one.

I realize this is a rather large PR. Please let me know if these changes are outside the scope of the repo or if there's anything I can do to make it easier to review.

kentslaney avatar Jul 15 '24 03:07 kentslaney