View source: R/transcribeServer.R
| transcribeServer | R Documentation | 
Make the Transcription Interface Interactive
transcribeServer(
  id = "transcribe",
  trigger = NULL,
  audioFile,
  outFile,
  allowPause = FALSE,
  n_play = NULL,
  result = c("clear", "hide"),
  instructions =
    "Play the audio file. Then, enter what you heard in the box below.\n                                             Click the submit button when you are finished.",
  n_lines = 1,
  width = "100%",
  submitLab = "SUBMIT"
)
| id | The module id. Must be the same as  | 
| trigger | If not  | 
| audioFile | The file path to a file relative to the applications www directory. (The file must be in the www directory, but the path should not include the "www/" prefix). | 
| outFile | If not NULL (the default), a file path with the extension .rds, which will store the name of the audio file, the transcription entered, and the number of times the participant played the audio. | 
| allowPause | Boolean. Should the participant be given a button to pause the audio during the transcription? Defaults to FALSE. | 
| n_play | Integer. How many times can a participant play the audio file before clicking "submit"? Defaults to 1. | 
| result | One of "hide" or "clear". Should the interface be hidden or simply cleared (restored to its original state) when a participant clicks submit? | 
| instructions | Character. Instructions that will appear above the text entry area. Defaults to generic instructions for transcription. | 
| n_lines | Integer. The number of lines the text input area should occupy. Defaults to 1. Could be set higher for longer transcriptions, so the entire text entered remains visible to the participant. | 
| width | Character. Defaults to "100%", defines how much of the horizontal space the transcription interface will occupy. | 
| submitLab | The label on the submit button. Defaults to "SUBMIT". | 
Returns a set of reactive values including the name of the audio file, the text the participant entered, and the number of times they clicked play.
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.