Skip to content

Instantly share code, notes, and snippets.

@agricolamz
Created March 29, 2024 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agricolamz/1cddab5f08a7eb6a1ed92463ff7b2c70 to your computer and use it in GitHub Desktop.
Save agricolamz/1cddab5f08a7eb6a1ed92463ff7b2c70 to your computer and use it in GitHub Desktop.
speech_to_text <- function(audio,
output_name = "output",
model_path = "ggml-large-v3.bin"){
library(tidyverse)
library(audio.whisper)
# convert to the format specs ---------------------------------------------
tmp <- tempdir()
str_glue("ffmpeg -i {audio} -ar 16000 -ac 1 -c:a pcm_s16le {tmp}/{output_name}.wav") |>
system()
# load and run model ------------------------------------------------------
model <- whisper(model_path)
result <- predict(model,
str_glue("{tmp}/{output_name}.wav"),
language = "ru")
# write down results ------------------------------------------------------
result$data |>
as.data.frame() |>
write_csv(str_glue("{output_name}.csv"))
result$params
print(result$timing)
}
speech_to_text(audio = "test.wav", output_name = "test")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment