Skip to content

Support stream input in Whisper serving and stream ffmpeg chunks - #361

Merged
jonatanklosko merged 6 commits into
mainfrom
jk-whisper-input-stream
Mar 12, 2024
Merged

Support stream input in Whisper serving and stream ffmpeg chunks#361
jonatanklosko merged 6 commits into
mainfrom
jk-whisper-input-stream

Conversation

@jonatanklosko

Copy link
Copy Markdown
Member

Closes #261.

This allows the Whisper serving to accept a stream of consecutive chunks. Importantly, this improves the {:file, path}, such that we read the file in chunks using ffmpeg, rather than loading it into memory all at once.

This PR drops support for a list if inputs, such as Nx.Serving.batched_run(MyServing, [{:file, path1}, {:file2, path2}]). This serving works on a higher level than usually, because a single chunked input is already multiple inputs to the model, so I think this is sane. Multiple inputs can be processed concurrently by calling batched_run from multiple processes.

I noticed a bug, specifically when streaming with timestamps and using a batch_size, we would ignore small segments after every batch.


@josevalim I went with the stream of consecutive chunks and handle accumulation + overlapping internally. I think it is preferable to keep the chunking details internal and I don't see a benefit of exposing it. If we shift accumulation to the user, they would basically need to do exactly that. For ffmpeg we would do that in bumblebee anyway, because accumulation is better than duplicating ffmpeg decoding work.

Comment thread lib/bumblebee/audio.ex Outdated
Comment thread lib/bumblebee/audio/speech_to_text_whisper.ex Outdated
Comment thread lib/bumblebee/audio/speech_to_text_whisper.ex Outdated

@josevalim josevalim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny comments but ship as you prefer!

Comment thread lib/bumblebee/audio.ex
@jonatanklosko
jonatanklosko merged commit f6791b2 into main Mar 12, 2024
@jonatanklosko
jonatanklosko deleted the jk-whisper-input-stream branch March 12, 2024 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stream audio chunk by chunk to Whisper

2 participants