Skip to content

Commit 2650830

Browse files
committed
add timing element in output of predict.whisper
1 parent 114c54d commit 2650830

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## CHANGES IN audio.whisper VERSION 0.2.2
22

33
- Add option to pass on float entropy_thold, logprob_thold, beam_size, best_of, split_on_word when doing the prediction
4+
- Output of the predict.whisper function now includes an element called timing indicating how long it took to do the transcription
45

56
## CHANGES IN audio.whisper VERSION 0.2.1-1
67

R/whisper.R

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#' \item{data: a data.frame with the transcription with columns segment, text, from and to}
1414
#' \item{tokens: a data.frame with the transcription tokens with columns segment, token_id, token, token_prob indicating the token probability given the context}
1515
#' \item{params: a list with parameters used for inference}
16+
#' \item{timing: a list with elements start, end and duration indicating how long it took to do the transcription}
1617
#' }
1718
#' @export
1819
#' @seealso \code{\link{whisper}}
@@ -27,13 +28,18 @@
2728
predict.whisper <- function(object, newdata, language = "auto", trim = FALSE, ...){
2829
stopifnot(length(newdata) == 1)
2930
stopifnot(file.exists(newdata))
31+
start <- Sys.time()
3032
out <- whisper_encode(model = object$model, path = newdata, language = language, ...)
3133
Encoding(out$data$text) <- "UTF-8"
3234
Encoding(out$tokens$token) <- "UTF-8"
3335
if(trim){
3436
out$data$text <- trimws(out$data$text)
3537
out$tokens$token <- trimws(out$tokens$token)
3638
}
39+
end <- Sys.time()
40+
out$timing <- list(transcription_start = start,
41+
transcription_end = end,
42+
transcription_duration = difftime(end, start, units = "mins"))
3743
class(out) <- "whisper_transcription"
3844
out
3945
}

0 commit comments

Comments
 (0)