Changeset 35546 for main/trunk
- Timestamp:
- 2021-10-01T15:58:34+13:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/TranscriptionItemEditor.vue
r35545 r35546 129 129 data() { 130 130 return { 131 words: [], 131 132 enableEditing: false, 132 133 lastHighlightedWordIndex: 0, … … 135 136 }, 136 137 computed: { 137 /**138 * Gets the words in a transcription.139 * @param {TranscriptionViewModel} transcription The transcription.140 * @returns {Word[]}141 */142 words() {143 const metadata = this.transcription.metadata;144 145 if (metadata.length === 0) {146 return;147 }148 149 /** @type {Word[]} */150 const words = [];151 152 let currentWord = "";153 let currStartTime = metadata[0].start_time;154 155 for (let i = 0; i < metadata.length; i++) {156 const mChar = metadata[i];157 158 if (mChar.char === " ") {159 words.push(new Word(currentWord, currStartTime, mChar.start_time));160 currentWord = "";161 162 if (i + 1 < metadata.length) {163 currStartTime = metadata[i + 1].start_time;164 }165 else {166 break;167 }168 }169 else {170 currentWord += mChar.char;171 }172 }173 174 // Push the last word, as most transcriptions will not end in a space (hence breaking the above algorithm)175 if (currentWord.length > 0) {176 const newWord = new Word(currentWord, currStartTime, metadata[metadata.length - 1].start_time)177 words.push(newWord);178 }179 180 return words;181 },182 138 currentPlaybackTime: { 183 139 get() { … … 208 164 }, 209 165 methods: { 166 167 /** 168 * Gets the words in a transcription. 169 * @param {TranscriptionViewModel} transcription The transcription. 170 * @returns {Word[]} 171 */ 172 getWords() { 173 const metadata = this.transcription.metadata; 174 175 if (metadata.length === 0) { 176 return; 177 } 178 179 /** @type {Word[]} */ 180 const words = []; 181 182 let currentWord = ""; 183 let currStartTime = metadata[0].start_time; 184 185 for (let i = 0; i < metadata.length; i++) { 186 const mChar = metadata[i]; 187 188 if (mChar.char === " ") { 189 words.push(new Word(currentWord, currStartTime, mChar.start_time)); 190 currentWord = ""; 191 192 if (i + 1 < metadata.length) { 193 currStartTime = metadata[i + 1].start_time; 194 } 195 else { 196 break; 197 } 198 } 199 else { 200 currentWord += mChar.char; 201 } 202 } 203 204 // Push the last word, as most transcriptions will not end in a space (hence breaking the above algorithm) 205 if (currentWord.length > 0) { 206 const newWord = new Word(currentWord, currStartTime, metadata[metadata.length - 1].start_time) 207 words.push(newWord); 208 } 209 210 return words; 211 }, 210 212 211 213 async playAudio(startTime) { … … 471 473 } 472 474 } 475 }, 476 beforeMount() { 477 this.words = this.getWords(); 473 478 } 474 479 }
Note:
See TracChangeset
for help on using the changeset viewer.