81 case GGML_LOG_LEVEL_ERROR:
84 case GGML_LOG_LEVEL_WARN:
106 struct whisper_context_params
params = whisper_context_default_params();
124 struct whisper_vad_context_params ctx_params = whisper_vad_default_context_params();
130 wctx->
vad_params = whisper_vad_default_params();
143 if (!strcmp(
"-",
dst))
155 if (!whisper_is_multilingual(wctx->
ctx_wsp)) {
158 "Multilingual model not provided. Non-English audio may not be correctly transcribed.\n");
161 "%s requested but multilingual model not provided.\n", wctx->
translate ?
"Translation" :
"Transcription");
169 "Whisper filter initialized: model: %s lang: %s queue: %" PRId64
" ms\n",
181 "Remaining audio buffer %d samples (%d seconds) after stopping\n",
186 whisper_vad_free(wctx->
ctx_vad);
206 if (!wctx->
ctx_wsp || samples == 0)
210 const float duration = (
float) samples / WHISPER_SAMPLE_RATE;
213 "run transcription at %" PRId64
" ms, %d/%d samples (%.2f seconds)...\n",
216 struct whisper_full_params
params = whisper_full_default_params(WHISPER_SAMPLING_GREEDY);
221 params.print_progress = 0;
222 params.print_realtime = 0;
223 params.print_timestamps = 0;
233 const int n_segments = whisper_full_n_segments(wctx->
ctx_wsp);
234 char *segments_text =
NULL;
236 for (
int i = 0;
i < n_segments; ++
i) {
237 const char *text = whisper_full_get_segment_text(wctx->
ctx_wsp,
i);
248 if (wctx->
max_len > 0 && (strcmp(text_cleaned,
"[") == 0 || strcmp(text_cleaned,
"]") == 0 ||
249 strcmp(text_cleaned,
"BLANK") == 0 || strcmp(text_cleaned,
"_") == 0 ||
250 strcmp(text_cleaned,
"AUDIO") == 0)) {
255 const bool turn = whisper_full_get_segment_speaker_turn_next(wctx->
ctx_wsp,
i);
256 const int64_t t0_ms = whisper_full_get_segment_t0(wctx->
ctx_wsp,
i) * 10;
257 const int64_t t1_ms = whisper_full_get_segment_t1(wctx->
ctx_wsp,
i) * 10;
260 timestamp_ms + t0_ms, timestamp_ms + t1_ms, turn ?
" (turn)" :
"", text_cleaned);
263 char *new_text =
av_asprintf(
"%s%s", segments_text, text_cleaned);
265 segments_text = new_text;
270 const int64_t start_t = timestamp_ms + t0_ms;
271 const int64_t end_t = timestamp_ms + t1_ms;
277 (
"%d\n%02" PRId64
":%02" PRId64
":%02" PRId64
",%03" PRId64
" --> %02" PRId64
":%02" PRId64
":%02" PRId64
",%03" PRId64
"\n%s\n\n",
278 wctx->
index, start_t / 3600000,
279 (start_t / 60000) % 60, (start_t / 1000) % 60,
280 start_t % 1000, end_t / 3600000, (end_t / 60000) % 60,
281 (end_t / 1000) % 60, end_t % 1000, text_cleaned);
285 buf =
av_asprintf(
"{\"start\":%" PRId64
",\"end\":%" PRId64
",\"text\":\"%s\"}\n", start_t, end_t, text_cleaned);
321 const int samples =
frame->nb_samples;
331 (
AVRational) {inlink->time_base.den, inlink->time_base.num});
338 struct whisper_vad_segments *segments = whisper_vad_segments_from_samples(wctx->
ctx_vad,
347 int n_segments = whisper_vad_segments_n_segments(segments);
349 if (n_segments > 0) {
350 const float start_ms = whisper_vad_segments_get_segment_t0(segments, 0) * 10.0;
351 const float end_ms = whisper_vad_segments_get_segment_t1(segments, n_segments - 1) * 10.0;
352 int end_pos = (int) (end_ms * WHISPER_SAMPLE_RATE / 1000);
354 if (end_pos <= wctx->audio_buffer_fill_size -
357 "VAD detected %d segments, start: %.0f ms, end: %.0f ms (buffer: %d ms)\n",
363 whisper_vad_free_segments(segments);
456#define OFFSET(x) offsetof(WhisperContext, x)
457#define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
458#define HOURS 3600000000
462 {
"language",
"Language for transcription ('auto' for auto-detect)",
OFFSET(language_str),
AV_OPT_TYPE_STRING, {.str =
"auto"}, .flags =
FLAGS },
463 {
"translate",
"Translate from source language to English",
OFFSET(translate),
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, .flags =
FLAGS },
478 .class_name =
"whisper",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
SwsAArch64OpImplParams params
static enum AVSampleFormat sample_fmts[]
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static const char *const format[]
const FFFilter ff_af_whisper
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
static void uninit(AVFilterContext *ctx)
static const AVOption whisper_options[]
static const AVClass whisper_class
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int activate(AVFilterContext *ctx)
static void run_transcription(AVFilterContext *ctx, AVFrame *frame, int samples)
static void cb_log(enum ggml_log_level level, const char *text, void *user_data)
static int push_last_frame(AVFilterLink *outlink)
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
size_t ff_inlink_queued_frames(AVFilterLink *link)
Get the number of frames available on the link.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Main libavfilter public API header.
int avio_open(AVIOContext **s, const char *filename, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
#define AVIO_FLAG_WRITE
write-only
#define AVIO_FLAG_DIRECT
Use direct mode.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
char * av_asprintf(const char *fmt,...)
Convenience header that includes libavutil's core.
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define i(width, name, range_min, range_max)
static int FUNC user_data(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawUserData *current)
Public libavutil channel layout APIs header.
static const int sample_rates[]
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
AVSampleFormat
Audio sample formats.
int av_samples_set_silence(uint8_t *const *audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
size_t static size_t av_strnlen(const char *s, size_t len)
Get the count of continuous non zero chars starting from the beginning.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
char * av_strireplace(const char *str, const char *from, const char *to)
Locale-independent strings replace.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE
Internal time base represented as integer.
#define LIBAVUTIL_VERSION_INT
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FORWARD_WANTED(outlink, inlink)
Forward the frame_wanted_out flag from an output link to an input link.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
#define FFERROR_NOT_READY
Filters implementation helper functions and internal structures.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
#define FILTER_QUERY_FUNC2(func)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int ff_thread_once(char *control, void(*routine)(void))
static atomic_int av_log_level
Memory handling functions.
static void input_data(MLPEncodeContext *ctx, MLPSubstream *s, uint8_t **const samples, int nb_samples)
Wrapper function for inputting data in two different bit-depths.
An AVChannelLayout holds information about the channel layout of audio data.
Describe the class of an AVClass context structure.
A link between two filters.
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
int sample_rate
samples per second
AVFilterContext * dst
dest filter
This structure describes decoded (raw) audio or video data.
int direct
avio_read and avio_write should if possible be satisfied directly instead of going through a buffer,...
Rational number (pair of numerator and denominator).
int audio_buffer_queue_size
struct whisper_vad_params vad_params
int audio_buffer_vad_size
int64_t audio_buffer_start_ms
struct whisper_context * ctx_wsp
int64_t vad_min_silence_duration
struct whisper_vad_context * ctx_vad
int64_t vad_min_speech_duration
int audio_buffer_fill_size
AVIOContext * avio_context
#define av_malloc_array(a, b)
static AVFormatContext * ctx