Changeset 35243
- Timestamp:
- 2021-08-03T17:23:54+12:00 (3 years ago)
- Location:
- main/trunk/model-interfaces-dev/atea
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/model-interfaces-dev/atea/js/asr/TranscribeService.js
r35238 r35243 1 /** 2 * The transcription object returned from our transcription endpoint. 3 * 4 * @typedef {Object} TranscriptionModel 5 * @property {String} transcription The transcription. 6 * @property {{char: String, start_time: Number}[]} metadata The character metadata. 7 * @property {String} file_name The name of the file that was transcribed. 8 */ 9 1 10 /** 2 11 * A service that uploads audio files in a multipart request to the Korero Maori API Interface servlet, and interprets the result. … … 14 23 * 15 24 * @param {FileList} files The files to upload. 16 * @returns {Promise< string>} A promise with an HTMLresponse.25 * @returns {Promise<TranscriptionModel>} A promise for an object representation of the JSON response. 17 26 */ 18 27 async doFetchUpload(files) … … 42 51 43 52 return response.json(); 53 } 54 55 /** 56 * @callback TranscriptionPromiseCallback 57 * @param {Promise<Response>} promise A fetch promise containing an HTTP response. 58 * @param {String} filename The file that this transcription is for. 59 * @returns {void} 60 */ 61 62 /** 63 * 64 * @param {FileList} files The files to upload 65 * @param {TranscriptionPromiseCallback} callback A callback made with the fetch promise. 66 */ 67 doIndividualFetchUpload(files, callback) 68 { 69 const that = this; 70 71 for (let f of files) 72 { 73 const formData = new FormData(); 74 formData.append("audioFile", f, f.name); 75 formData.append("audioFileKeys", "audioFile"); 76 77 let promise = fetch 78 ( 79 that.queryUrl, 80 { 81 method: "POST", 82 body: formData 83 } 84 ) 85 callback(promise, f.name); 86 } 44 87 } 45 88 -
main/trunk/model-interfaces-dev/atea/js/asr/asr-controller.js
r35238 r35243 20 20 * @param {Event} ev The event 21 21 * @returns {void} 22 */23 24 /**25 * The transcription object returned from our transcription endpoint.26 *27 * @typedef {Object} TranscriptionModel28 * @property {String} transcription The transcription.29 * @property {{char: String, start_time: Number}[]} metadata The character metadata.30 * @property {String} file_name The name of the file that was transcribed.31 22 */ 32 23 … … 63 54 $(FILE_UPLOAD_PROGRESS_CONTAINER_NAME).removeClass("asr-hidden"); 64 55 65 transcribeService.doFetchUpload(files) 56 // Remove old transcriptions 57 const parent = document.querySelector("#transcriptionsList"); 58 while (parent.lastChild) { 59 parent.removeChild(parent.lastChild); 60 } 61 62 transcribeService.doIndividualFetchUpload(files, (promise, fileName) => { 63 promise 66 64 .then 67 65 ( 68 transcriptions => { 69 // Remove old transcriptions 70 const parent = document.querySelector("#transcriptionsList"); 71 while (parent.lastChild) { 72 parent.removeChild(parent.lastChild); 73 } 66 async response => 67 { 68 /** @type {TranscriptionModel[]} */ 69 const transcription = await response.json(); 74 70 75 // Insert each new transcription 76 for (let t of transcriptions) { 71 // Note that there will only be one transcription here, however the proxy API always returns a list. 72 for (let t of transcription) { 73 console.log("Inserting one transcription"); 77 74 insertTranscription(t); 78 75 } 79 },80 reason => {81 console.log(reason)82 76 } 83 77 ) 84 .catch(error => console.log("Failed to upload audio files for transcription: " + error)) // TODO: display error to user 85 .finally(() => $(FILE_UPLOAD_PROGRESS_CONTAINER_NAME).addClass("asr-hidden")); 78 .catch 79 ( 80 reason => 81 { 82 insertError(fileName); 83 console.log(`Transcription for file ${fileName} failed with reason ${reason}`); 84 } 85 ); 86 }) 87 88 // transcribeService.doFetchUpload(files) 89 // .then 90 // ( 91 // transcriptions => { 92 // // Insert each new transcription 93 // for (let t of transcriptions) { 94 // insertTranscription(t); 95 // } 96 // }, 97 // reason => { 98 // console.log(reason) 99 // } 100 // ) 101 // .catch(error => console.log("Failed to upload audio files for transcription: " + error)) // TODO: display error to user 102 // .finally(() => $(FILE_UPLOAD_PROGRESS_CONTAINER_NAME).addClass("asr-hidden")); 86 103 return false; 87 104 } … … 90 107 const transcriptionTemplate = document.querySelector('#transcriptionTemplate'); 91 108 const metadataTemplate = document.querySelector("#metadataTemplate"); 109 const errorTemplate = document.querySelector("#errorTemplate"); 92 110 93 111 /** 94 * Inserts a transcription object into the DOM 112 * Inserts a transcription object into the DOM. 95 113 * 96 114 * @param {TranscriptionModel} transcription The transcription to insert. 97 * @returns {void}98 115 */ 99 116 function insertTranscription(transcription) … … 135 152 } 136 153 154 /** 155 * Inserts a transcription error into the DOM. 156 * 157 * @param {String} fileName 158 */ 159 function insertError(fileName) 160 { 161 // Get the transcription list and template 162 let list = document.querySelector("#transcriptionsList"); 163 164 if (list == null || errorTemplate == null) { 165 console.error("Could not find transcription list and/or error template"); 166 return; 167 } 168 169 // Insert a new transcription row 170 let clone = errorTemplate.content.firstElementChild.cloneNode(true); 171 let spans = clone.querySelectorAll("span"); 172 spans[0].textContent = fileName; 173 174 list.appendChild(clone); 175 } 176 137 177 $(FILE_UPLOAD_INPUT_NAME).on("input", toggleUploadButtonState); 138 178 -
main/trunk/model-interfaces-dev/atea/style/asr.css
r35238 r35243 25 25 .transcription-list-item .spaced-block:last-child { 26 26 margin-bottom: 0; 27 } 28 29 .error-list-item { 30 list-style-type: none; 31 background-color: rgba(255, 0, 0, 0.329); 32 border: 1px solid rgba(255, 0, 0, 0.651); 33 border-radius: 5px; 34 margin-bottom: 5px; 35 padding: 1em; 27 36 } 28 37 -
main/trunk/model-interfaces-dev/atea/transform/pages/asr.xsl
r35238 r35243 33 33 <!-- the page content --> 34 34 <xsl:template match="/page"> 35 36 <!-- <xsl:choose>37 <xsl:when test="$this-element/displayItemList/displayItem[@name='icon']">38 <img border="0">39 <xsl:attribute name="src"><xsl:value-of select="$this-element/metadataList/metadata[@name='httpPath']"/>/images/<xsl:value-of select="$this-element/displayItemList/displayItem[@name='icon']"/></xsl:attribute>40 <xsl:attribute name="alt">41 <xsl:value-of select="$this-element/displayItemList/displayItem[@name='name']"/>42 </xsl:attribute>43 <xsl:attribute name="title">44 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'aboutpage')"/>45 </xsl:attribute>46 </img>47 </xsl:when>48 </xsl:choose> -->49 50 35 <xsl:call-template name="audio-upload"/> 51 36 </xsl:template> … … 53 38 <!-- Template for processing audio file uploads --> 54 39 <xsl:template name="audio-upload"> 55 <link rel="stylesheet" href="interfaces/{$interface_name}/style/asr.css" type="text/css" />40 <link rel="stylesheet" href="interfaces/{$interface_name}/style/asr.css" type="text/css" /> 56 41 57 42 <div> … … 70 55 <div id="transcriptionsDisplayContainer"> 71 56 <ul id="transcriptionsList" class="transcription-list"></ul> 72 57 73 58 <template id="transcriptionTemplate"> 74 59 <li class="transcription-list-item"> … … 96 81 </template> 97 82 83 <template id="errorTemplate"> 84 <li class="error-list-item"> 85 <div> 86 Transcription failed!<br /> 87 <b>File: </b><span></span> 88 </div> 89 </li> 90 </template> 91 98 92 <template id="metadataTemplate"> 99 93 <tr>
Note:
See TracChangeset
for help on using the changeset viewer.