View source: R/evalWavServer.R
evalWavServer | R Documentation |
Give feedback to participants on recording quality
evalWavServer(
wave,
counter = 1,
min_sf = 44100,
snr_best = 30,
snr_good = 20,
max_clip = 0.01,
tries = Inf,
onFail = "stop"
)
wave |
Required. Either a |
counter |
Required. A value that tells this function how many tries a participant has had so far. |
min_sf |
What is the minimum sample rate (in Hz) that you will allow for the recording? If a user's browser will not allow audio recording at this high of a sample rate, the user will get an error message. Set to 0 if you do not want to exclude participants who record at low sampling rates. |
snr_best |
Integer. If eval=TRUE, what is the minimum SNR (dB) required for the recording to be considered of the best quality? Defaults to 30. |
snr_good |
Integer. If eval=TRUE, what is the minimum SNR (dB) required for the recording to be considered acceptable? Must be less than |
max_clip |
Numeric. What proportion of the frames can be clipped and the recording still be acceptable? Defaults to .01. |
tries |
Integer. How many tries should the user get to create a quality recording? |
onFail |
What kind of message should the user receive if they try to record the maximum number of |
One of three reactive values: "pass"=recording of sufficient quality; "warn"=recording of insufficient quality, but the participant has had fewer attempts than the number of tries
; or "fail"=the recording is of insufficient quality and the participant has used all available attempts.
if (interactive()) {
library(shiny)
library(shinyjs)
# Build UI
ui <- fluidPage(
## Get background javascript ready
useShinyjs(),
tags$head(
useRecorder()
),
actionButton("next_trial", "NEXT"),
## Setup page layout
hidden(div(id = "trialDiv",
style = "text-align:center;",
hidden(div(id = "textDiv",
h4("Please record yourself reading this sentence aloud:"),
h2(textOutput(outputId = "read_this")))),
## Create the buttons for controlling the recording
actionButton(inputId = "start",
label = "start"),
### Hide the stop button until user clicks start
hidden(actionButton(inputId = "stop",
label = "stop"))
))
)
# The Server function
server <- function(input, output, session) {
## Create an object that will count trials
rvs <- reactiveValues(trial_n = 0)
## When the participant clicks "NEXT"...
observeEvent(input$next_trial, {
### Increase the trial number
rvs$trial_n <- rvs$trial_n + 1
### Show the recording interface
showElement("trialDiv")
### Hide the next button
hide("next_trial")
})
## When the start button is clicked
observeEvent(input$start, {
### Start the recording
startRec()
### Disable the start button
disable("start")
### Show the stop button
delay(500, showElement("stop"))
})
## When the user gives permission to record....
observeEvent(input[["rec-ready"]], {
### Show the text they should read
showElement("textDiv")
output$read_this <- renderText({paste0("This is recording ",
rvs$trial_n, ".")})
})
## When the user clicks stop
observeEvent(input$stop, {
### Stop recording
stopRec(filename = paste0("rec", rvs$trial_n, ".wav"))
### Enable the start button
enable("start")
### Hide the stop button
hide("stop")
hide("textDiv")
})
## Once the wav file exists...
observeEvent(input[["rec-done"]], {
### Evaluate the recording
evalWavServer(wave = paste(input[["rec-done"]]))
})
## Once the wav file has been evaluated...
observeEvent(input[["evalWav-result"]], {
### If the recording is of sufficient quality...
if (input[["evalWav-result"]] == "pass") {
#### Hide the recording interface
hide("trialDiv")
#### And show the "next" button so that the participant can record the next file
showElement("next_trial")
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.