Changeset 35259 for main/trunk/model-interfaces-dev
- Timestamp:
- 2021-08-06T11:10:25+12:00 (3 years ago)
- 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 1 6 /** 2 7 * The transcription object returned from our transcription endpoint. … … 32 37 constructor() 33 38 { 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. */ 36 43 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 38 47 } 39 48 … … 55 64 for (let file of files) 56 65 { 57 if (fileCounter == this.MAX_BATCH_COUNT || byteCounter > this. MAX_BATCH_SIZE) // 5 MiB66 if (fileCounter == this.MAX_BATCH_COUNT || byteCounter > this.BATCH_BYTE_LIMIT) // 5 MiB 58 67 { 59 68 yield await this.transcribeFiles(filesToSubmit); … … 121 130 } 122 131 123 // OBSOLETE. Kept for reference purposes . See doFetchUpload instead.132 // OBSOLETE. Kept for reference purposes on XMLHttpRequest usage. See doFetchUpload instead. 124 133 // 125 134 // 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 */ 2 5 // @ts-nocheck 3 6 … … 48 51 const transcriptionAudioSourceElement = document.getElementById("transcriptionAudioSource"); 49 52 53 let cachedAudioFileList = new Map(); 54 50 55 async function doAudioUpload() 51 56 { 57 /** @type {FileList} */ 52 58 const files = $(FILE_UPLOAD_INPUT_NAME)[0].files; 53 59 54 transcriptionAudioSourceElement.src = URL.createObjectURL(files[0]); 55 transcriptionAudioElement.load(); 56 60 // Disable the file input while transcribing, and show the progress bar 57 61 $(FILE_UPLOAD_INPUT_NAME).prop("disabled", true); 58 62 $(FILE_UPLOAD_PROGRESS_CONTAINER_NAME).removeClass("asr-hidden"); 59 63 60 64 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. 62 72 try 63 73 { 64 for await (const transcriptionBundleof transcribeService.batchTranscribeFiles(files))74 for await (const batch of transcribeService.batchTranscribeFiles(files)) 65 75 { 66 for (const t of transcriptionBundle)76 for (const t of batch) 67 77 { 68 78 if (!t.success) { … … 81 91 } 82 92 93 // Hide the progress bar and re-enable the file input. 83 94 $(FILE_UPLOAD_PROGRESS_CONTAINER_NAME).addClass("asr-hidden"); 84 95 $(FILE_UPLOAD_INPUT_NAME).prop("disabled", false); … … 93 104 function clearTranscriptions() 94 105 { 106 cachedAudioFileList = new Map(); 95 107 while (transcriptionsList.lastChild) { 96 108 transcriptionsList.removeChild(transcriptionsList.lastChild); … … 123 135 // Insert metadata rows 124 136 for (const metadata of transcription.metadata) { 125 metadataList.appendChild(buildMetadataNode(metadata ));137 metadataList.appendChild(buildMetadataNode(metadata, transcription.file_name)); 126 138 } 127 139 … … 150 162 151 163 button.dataset.fileName = fileName; 152 button.onclick = function( )164 button.onclick = function(e) 153 165 { 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 154 183 transcriptionAudioElement.currentTime = metadata.start_time; 155 184 transcriptionAudioElement.play(); … … 173 202 * 174 203 * @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. 176 205 */ 177 206 function insertError(fileName, statusMessage) -
main/trunk/model-interfaces-dev/atea/transform/pages/asr.xsl
r35258 r35259 54 54 55 55 <div id="transcriptionsDisplayContainer"> 56 <audio id="transcriptionAudio" controls="controls">57 <source id="transcriptionAudioSource" src=""/>56 <audio id="transcriptionAudio"> 57 <source id="transcriptionAudioSource" /> 58 58 </audio> 59 59
Note:
See TracChangeset
for help on using the changeset viewer.