Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions lib/bumblebee/audio.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ defmodule Bumblebee.Audio do

* a 1-dimensional `Nx.Tensor` with audio samples

* an enumerable of 1-dimensional `Nx.Tensor`s, represending a
continuous stream of input. The tensors are not required to
have the same number of samples, the serving takes care of
accumulating and chunking the input as needed. This input is
only supported when chunking is enabled with the `:chunk_num_seconds`
option

* `{:file, path}` with path to an audio file (note that this
requires `ffmpeg` installed)

"""
@type audio :: Nx.t() | {:file, String.t()}
@type audio :: Nx.t() | Enumerable.t(Nx.t()) | {:file, String.t()}

@type speech_to_text_whisper_input ::
audio() | %{:audio => audio(), optional(:seed) => integer() | nil}
Expand All @@ -31,7 +38,11 @@ defmodule Bumblebee.Audio do
Builds serving for speech-to-text generation with Whisper models.

The serving accepts `t:speech_to_text_whisper_input/0` and returns
`t:speech_to_text_whisper_output/0`. A list of inputs is also supported.
`t:speech_to_text_whisper_output/0`.

This serving always accepts a single input. A list of tensors is
interpreted as continuous chunks. To transcribe multiple inputs
concurrently use `Nx.Serving.batched_run/2`.

## Options

Expand All @@ -48,6 +59,15 @@ defmodule Bumblebee.Audio do
in the total `:chunk_num_seconds`. Defaults to 1/6 of
`:chunk_num_seconds`

* `:client_batch_size` - the number of input chunks the client
jonatanklosko marked this conversation as resolved.
Show resolved Hide resolved
should gather and run at once. When streaming an input that is
already available (such as a file), you can use any value without
introducing a delay. A good default is to use the same value as
`opts[:compile][:batch_size]`. When streaming an input that is
being produced live, you may want to process chunks as soon as
they are available, in which case set this option to `1`. Defaults
to `opts[:compile][:batch_size]` if present, otherwise to `1`

* `:language` - the language of the speech, when known upfront.
Should be given as ISO alpha-2 code as string. By default no
language is assumed and it is inferred from the input
Expand Down
Loading
Loading