Ignore:
Timestamp:
2021-08-06T11:10:25+12:00 (3 years ago)
Author:
davidb
Message:

Implement support for switching between audio files

Location:
main/trunk/model-interfaces-dev/atea
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-interfaces-dev/atea/js/asr/TranscribeService.js

    r35253 r35259  
     1/**
     2 * @file Defines components that are used to interact with the transcription proxy servlet.
     3 * @author Carl Stephens
     4 */
     5
    16/**
    27 * The transcription object returned from our transcription endpoint.
     
    3237    constructor()
    3338    {
    34         /** @type {String} The URL to which query POST requests should be made */
    35         this.queryUrl = "/gs3-koreromaori/transcribe/test";
     39        /** @type {String} The URL to which query POST requests should be made. */
     40        this.queryUrl = "/gs3-koreromaori/transcribe";
     41
     42        /** @type {Number} The maximum number of files which can be transcribed in one request to the API. */
    3643        this.MAX_BATCH_COUNT = 3;
    37         this.MAX_BATCH_SIZE = 5242880; // 5 MiB
     44
     45        /** @type {Number} The soft upper limit on how many bytes can be submitted in one request. */
     46        this.BATCH_BYTE_LIMIT = 5242880; // 5 MiB
    3847    }
    3948
     
    5564        for (let file of files)
    5665        {
    57             if (fileCounter == this.MAX_BATCH_COUNT || byteCounter > this.MAX_BATCH_SIZE) // 5 MiB
     66            if (fileCounter == this.MAX_BATCH_COUNT || byteCounter > this.BATCH_BYTE_LIMIT) // 5 MiB
    5867            {
    5968                yield await this.transcribeFiles(filesToSubmit);
     
    121130    }
    122131
    123     // OBSOLETE. Kept for reference purposes. See doFetchUpload instead.
     132    // OBSOLETE. Kept for reference purposes on XMLHttpRequest usage. See doFetchUpload instead.
    124133    //
    125134    // Based on https://stackoverflow.com/questions/2320069/jquery-ajax-file-upload
  • main/trunk/model-interfaces-dev/atea/js/asr/asr-controller.js

    r35258 r35259  
    1 // The controller for asr.xsl
     1/**
     2 * @file Controller logic for asr.xsl.
     3 * @author Carl Stephens
     4 */
    25// @ts-nocheck
    36
     
    4851const transcriptionAudioSourceElement = document.getElementById("transcriptionAudioSource");
    4952
     53let cachedAudioFileList = new Map();
     54
    5055async function doAudioUpload()
    5156{
     57    /** @type {FileList} */
    5258    const files = $(FILE_UPLOAD_INPUT_NAME)[0].files;
    5359   
    54     transcriptionAudioSourceElement.src = URL.createObjectURL(files[0]);
    55     transcriptionAudioElement.load();
    56    
     60    // Disable the file input while transcribing, and show the progress bar
    5761    $(FILE_UPLOAD_INPUT_NAME).prop("disabled", true);
    5862    $(FILE_UPLOAD_PROGRESS_CONTAINER_NAME).removeClass("asr-hidden");
    5963   
    6064    clearTranscriptions();
    61    
     65
     66    // Cache the file list so that we can playback audio in the future
     67    for (const file of files) {
     68        cachedAudioFileList.set(file.name, file)
     69    }
     70   
     71    // Transcribe each audio file in batches.
    6272    try
    6373    {
    64         for await (const transcriptionBundle of transcribeService.batchTranscribeFiles(files))
     74        for await (const batch of transcribeService.batchTranscribeFiles(files))
    6575        {
    66             for (const t of transcriptionBundle)
     76            for (const t of batch)
    6777            {
    6878                if (!t.success) {
     
    8191    }
    8292   
     93    // Hide the progress bar and re-enable the file input.
    8394    $(FILE_UPLOAD_PROGRESS_CONTAINER_NAME).addClass("asr-hidden");
    8495    $(FILE_UPLOAD_INPUT_NAME).prop("disabled", false);
     
    93104function clearTranscriptions()
    94105{
     106    cachedAudioFileList = new Map();
    95107    while (transcriptionsList.lastChild) {
    96108        transcriptionsList.removeChild(transcriptionsList.lastChild);
     
    123135    // Insert metadata rows
    124136    for (const metadata of transcription.metadata) {
    125         metadataList.appendChild(buildMetadataNode(metadata));
     137        metadataList.appendChild(buildMetadataNode(metadata, transcription.file_name));
    126138    }
    127139   
     
    150162   
    151163    button.dataset.fileName = fileName;
    152     button.onclick = function()
     164    button.onclick = function(e)
    153165    {
     166        // Have to traverse the event path, because the event target is the child element of the button.
     167        const requestedAudioFile = e.composedPath().find((t) => t instanceof HTMLButtonElement).dataset.fileName;
     168        const currentAudioFile = transcriptionAudioSourceElement.dataset.fileName;
     169
     170        // Load the appropiate audio if necessary.
     171        if (currentAudioFile != requestedAudioFile)
     172        {
     173            if (currentAudioFile) {
     174                URL.revokeObjectURL(currentAudioFile);
     175            }
     176
     177            const urlObject = URL.createObjectURL(cachedAudioFileList.get(requestedAudioFile));
     178            transcriptionAudioSourceElement.src = urlObject;
     179            transcriptionAudioSourceElement.dataset.fileName = requestedAudioFile;
     180            transcriptionAudioElement.load();
     181        }
     182
    154183        transcriptionAudioElement.currentTime = metadata.start_time;
    155184        transcriptionAudioElement.play();
     
    173202*
    174203* @param {String} fileName The file for which an error occured.
    175 * @param {String | undefined} statusMessage An informative error message to display.
     204* @param {String | null} statusMessage An informative error message to display.
    176205*/
    177206function insertError(fileName, statusMessage)
  • main/trunk/model-interfaces-dev/atea/transform/pages/asr.xsl

    r35258 r35259  
    5454
    5555        <div id="transcriptionsDisplayContainer">
    56             <audio id="transcriptionAudio" controls="controls">
    57                 <source id="transcriptionAudioSource" src="" />
     56            <audio id="transcriptionAudio">
     57                <source id="transcriptionAudioSource" />
    5858            </audio>
    5959
Note: See TracChangeset for help on using the changeset viewer.