Skip to content

whisper-cli : align token timestamps with VAD ts #3218

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion examples/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,13 @@ static void output_json(
value_s("text", whisper_token_to_str(ctx, token.id), false);
if(token.t0 > -1 && token.t1 > -1) {
// If we have per-token timestamps, write them out
times_o(token.t0, token.t1, false);
if (params.vad) {
times_o(vad_ts_to_original_ts(token.t0, ctx),
vad_ts_to_original_ts(token.t1, ctx),
false);
} else {
times_o(token.t0, token.t1, false);
}
}
value_i("id", token.id, false);
value_f("p", token.p, false);
Expand Down
2 changes: 2 additions & 0 deletions include/whisper.h
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,8 @@ extern "C" {
WHISPER_API float whisper_vad_segments_get_segment_t0(struct whisper_vad_segments * segments, int i_segment);
WHISPER_API float whisper_vad_segments_get_segment_t1(struct whisper_vad_segments * segments, int i_segment);

WHISPER_API int64_t vad_ts_to_original_ts(int64_t vad_ts, struct whisper_context * ctx);

WHISPER_API void whisper_vad_free_segments(struct whisper_vad_segments * segments);
WHISPER_API void whisper_vad_free (struct whisper_vad_context * ctx);

Expand Down
4 changes: 4 additions & 0 deletions src/whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7968,6 +7968,10 @@ int64_t whisper_full_get_segment_t1(struct whisper_context * ctx, int i_segment)
return whisper_full_get_segment_t1_from_state(ctx->state, i_segment);
}

int64_t vad_ts_to_original_ts(int64_t vad_ts, struct whisper_context * ctx) {
return map_processed_to_original_time(vad_ts, ctx->state->vad_mapping_table);
}

bool whisper_full_get_segment_speaker_turn_next_from_state(struct whisper_state * state, int i_segment) {
return state->result_all[i_segment].speaker_turn_next;
}
Expand Down
Loading