Changeset 35545 for main/trunk
- Timestamp:
- 2021-10-01T15:55:02+13:00 (3 years ago)
- Location:
- main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/TranscriptionItemEditor.vue
r35542 r35545 130 130 return { 131 131 enableEditing: false, 132 words: [],133 132 lastHighlightedWordIndex: 0, 134 133 selectedIndex: 0 … … 136 135 }, 137 136 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 }, 138 182 currentPlaybackTime: { 139 183 get() { … … 164 208 }, 165 209 methods: { 210 166 211 async playAudio(startTime) { 167 212 await AudioPlayback.play(this.transcription.id, startTime); 168 213 }, 214 169 215 getSurroundingWords(index) { 170 216 const BUFFER = 2; // The number of words to take on each side … … 182 228 return this.words.slice(min, max); 183 229 }, 230 184 231 /** 185 232 * Invoked when the value of a word changes. … … 326 373 } 327 374 }, 375 328 376 mergeWordForward(word, index) { 329 377 if (this.words.length < 2) { … … 337 385 this.setFocus(index, false); 338 386 }, 387 339 388 mergeWordBackward(word, index) { 340 389 if (this.words.length < 2) { … … 348 397 this.setFocus(index, true); 349 398 }, 399 350 400 onEditorFocus(index) { 351 401 if (this.currentPlaybackTime < this.words[index].startTime || this.currentPlaybackTime > this.words[index].endTime) { … … 356 406 this.selectedIndex = index; 357 407 }, 408 358 409 onEditorFocusOut(index) { 359 410 // Remove empty words when they lose focus … … 395 446 } 396 447 } 448 397 449 }, 398 450 watch: { … … 419 471 } 420 472 } 421 },422 beforeMount() {423 this.words = getWords(this.transcription);424 473 } 425 474 } 426 427 /**428 * Gets the words in a transcription.429 * @param {TranscriptionViewModel} transcription The transcription.430 * @returns {Word[]}431 */432 export function getWords(transcription) {433 /** @type {Word[]} */434 const words = [];435 436 let lastWord = "";437 let currStartTime = 0;438 439 for (const metadata of transcription.metadata) {440 if (metadata.char === " ") {441 words.push(new Word(lastWord, currStartTime, metadata.start_time));442 443 lastWord = "";444 currStartTime = metadata.start_time;445 }446 else {447 lastWord += metadata.char;448 }449 }450 451 // Push the last word, as most transcriptions will not end in a space (hence breaking the above algorithm)452 if (lastWord.length > 0) {453 const newWord = new Word(lastWord, currStartTime, transcription.metadata[transcription.metadata.length - 1].start_time)454 words.push(newWord);455 }456 457 return words;458 }459 475 </script> -
main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/WordTimingSelector.vue
r35543 r35545 9 9 </div> 10 10 11 <span v-if="isMounted && !isProduction" class="material-icons mdi-m word-handle" :style="{ left: leftHandleLeft }" 12 @mousedown="canShiftMinValue = true"> 13 first_page 14 </span> 15 <span v-if="isMounted && !isProduction" class="material-icons mdi-m word-handle" :style="{ left: rightHandleLeft }" 16 @mousedown="canShiftMaxValue = true"> 17 last_page 18 </span> 11 <div class="word-attachment-container" :style="{ left: leftHandleLeft }"> 12 <span>{{ wordStartTime }}</span> 13 <span v-if="isMounted && !isProduction" class="material-icons mdi-m word-handle" @mousedown="canShiftMinValue = true"> 14 first_page 15 </span> 16 </div> 17 18 <div class="word-attachment-container" :style="{ left: rightHandleLeft }"> 19 <span v-if="isMounted && !isProduction" class="material-icons mdi-m word-handle" @mousedown="canShiftMaxValue = true"> 20 last_page 21 </span> 22 <span>{{ wordEndTime }}</span> 23 </div> 19 24 </div> 20 25 … … 51 56 } 52 57 58 .word-attachment-container { 59 position: absolute; 60 top: -105%; 61 display: flex; 62 align-items: center 63 } 64 53 65 .word-handle { 54 66 @extend .theme-flat; 55 56 position: absolute;57 top: -105%;58 67 59 68 color: var(--fg-color); … … 136 145 return Util.formatSecondsTimeString(this.surroundingWords[this.surroundingWords.length - 1].endTime, false, 2); 137 146 }, 147 wordStartTime() { 148 return Util.formatSecondsTimeString(this.word.startTime, false, 2); 149 }, 150 wordEndTime() { 151 return Util.formatSecondsTimeString(this.word.endTime, false, 2); 152 }, 138 153 leftHandleLeft() { 139 return `calc(${this.myWord.left}px - 1em)`;154 return `calc(${this.myWord.left}px - 5.5em)`; 140 155 }, 141 156 rightHandleLeft() {
Note:
See TracChangeset
for help on using the changeset viewer.