View source: R/evalTranscServer.R
evalTranscServer | R Documentation |
Evaluate Transcription and Give Feedback in a Shiny App
evalTranscServer(
filename = NULL,
text,
correct,
alphaOnly = TRUE,
matchCase = FALSE,
attempts = NULL,
counter = 1,
rmIncorrect = TRUE,
passInputId = "evalTransc-pass",
warnInputId = "evalTransc-warn",
failInputId = "evalTransc-fail"
)
filename |
An RDS file output from |
text |
A character string to test against the correct transcription. Not necessary if |
correct |
A character string of the correct transcription to which |
alphaOnly |
Boolean. Should the transcription be compared only in alphabetic characters entered, ignoring any spaces, punctuation, or digits? Defaults to TRUE. |
matchCase |
Boolean. Should the comparison be case-sensitive? Defaults to FALSE. |
attempts |
Integer. How many attempts does the user get to enter a correct transcription? |
counter |
Integer. Usually a shiny reactive value. Number of attempts the participant has completed. |
rmIncorrect |
Boolean. Should files containing incorrect transcriptions be kept if the participant has attempts remaining? Defaults to TRUE. |
passInputId |
The input Id of the alert that will appear (and require a click before disappearing) if the participant gives the correct transcription. |
warnInputId |
The input Id of the alert that will appear (and require a click before disappearing) if the participant gives an incorrect transcription, but has attempts remaining. |
failInputId |
The input Id of the alert that will appear (and require a click before disappearing) if the participant gives an incorrect transcription and has no attempts remaining. |
A Boolean value indicating whether the transcription in filename
matches the value given in correct
(=1) or not (=0). This function will also return feedback to the user in dialog boxes, indicating success (if a correct transcription was entered); a warning (upon entry of an incorrect transcription, informing participants of how many attempts remain); or an error alert (indicating an incorrect transcription when all attempts have been used).
The parameter rmIncorrect
removes incorrect transcriptions BEFORE the participants' final attempt. This means that the final transcription the participant enters will never be deleted. This parameter was added because, without it, the program will evaluate the current attempt and all previous attempts that have been saved under a given filename, returning numerous feedback screens any time more than one attempt is completed.
data("samp_wav")
tuneR::writeWave(samp_wav, "sample.wav")
wwwPrep(from = "sample.wav")
if (interactive()) {
library(shiny)
library(speechcollectr)
library(shinyjs)
ui <- fluidPage(
actionButton("begin", "Begin"),
transcribeUI(id = "transcribe"),
h5("Click 'Begin' each time you want to transcribe.
The recording will not change from trial to trial."),
h5("To demonstrate the transcription evaluation procedure,
we'll use a different 'correct transcritiption' for each trial."),
h5("The correct answers for the first 4 trials are:
'a', 'ab', 'abc', 'abcd' (in that order).")
)
server <- function(input, output, session) {
rvs <- reactiveValues(n = 1, attempt = 1)
answers <- c("a", "ab", "abc", "abcd")
observeEvent(input$begin, {
disable("begin")
rvs$out <- transcribeServer(id="transcribe",
audioFile = "sample.wav",
n_play = 4,
outFile = paste0("sample", rvs$n, ".rds"),
result = "hide")
})
observeEvent(input[["transcribe-submit"]], {
delay(500,
correct <- evalTranscServer(filename = paste0("sample", rvs$n, ".rds"),
correct = answers[rvs$n],
attempts = 2,
counter = rvs$attempt,
passInputId = "pass",
warnInputId = "warn",
failInputId = "fail"))
})
}
observeEvent(input$pass, {
rvs$n <- rvs$n + 1
rvs$attempt <- 1
enable("begin")
})
observeEvent(input$warn, {
rvs$attempt <- rvs$attempt + 1
enable("begin")
})
shinyApp(ui = ui, server = server)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.