Skip to content

Commit

Permalink
Merge pull request #15 from bakaburg1:Dev
Browse files Browse the repository at this point in the history
Fix faulty transcription files handling
  • Loading branch information
bakaburg1 authored Feb 8, 2024
2 parents 253e887 + 0ca0573 commit 9df72b5
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions R/speech_to_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -387,20 +387,29 @@ use_azure_whisper_stt <- function(

# Check response status
if (response$status_code != 200) {
warning("Error in Azure Whisper API request: ",
httr::content(response, "text"))
if (response$status_code == 429 ||
grepl("temporarily unable to process", httr::content(response, "text"))
) {
message("Retrying in 30 seconds...")
Sys.sleep(30)
use_azure_whisper_stt(

warning("Error ", response$status_code, " in Azure Whisper API request: ",
httr::content(response, "text"), call. = FALSE, immediate. = TRUE)

wait_for <- stringr::str_extract(
httr::content(response, "text", encoding = "UTF-8"),
"\\d+(?= seconds)") |> as.numeric()

if (is.na(wait_for) && !interactive()) stop()

if (is.na(wait_for)) wait_for <- 30

message("Retrying in ", wait_for, " seconds...")

Sys.sleep(wait_for)

res <- use_azure_whisper_stt(
audio_file = audio_file,
language = language,
initial_prompt = initial_prompt,
temperature = temperature
)
} else stop()
temperature = temperature)

return(res)
}

# Return the response
Expand Down

0 comments on commit 9df72b5

Please # to comment.