Changeset 35432 for main


Ignore:
Timestamp:
2021-09-20T15:13:08+12:00 (3 years ago)
Author:
cstephen
Message:

Prevent duplicate transcriptions being created

Location:
main/trunk/model-interfaces-dev/atea/korero-maori-asr/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/App.vue

    r35431 r35432  
    1717        </div>
    1818
    19         <div v-if="showInfo" class="card border-accent">
     19        <div v-if="showInfo" class="paper">
    2020            A tool to transcribe audio recordings of spoken Māori. Basic support for editing the transcriptions is provided,
    2121            and they can be downloaded in multiple formats.
     
    8181.transcription-list-item {
    8282    transition: all 0.8s ease;
     83    margin-bottom: 1em;
     84
     85    &:last-child {
     86        margin-bottom: 0;
     87    }
    8388}
    8489
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/AudioUpload.vue

    r35429 r35432  
    138138            this.isTranscribing = true;
    139139
    140             await getTranscriptions(this.files, this.$store, this);
     140            await this.getTranscriptions(this.files);
    141141
    142142            this.files = []; // Clear the file list, as there is no reason the user would want to transcribe the same file multiple times over
     
    152152        dismissFailure(id) {
    153153            this.failures.delete(id);
     154        },
     155        /**
     156         * Gets the transcription of each submitted audio file.
     157         * @param {File[]} files The files to transcribe.
     158         */
     159        async getTranscriptions(files) {
     160            await Util.delay(1000); // TODO: Remove - UI testing purposes only
     161
     162            try {
     163                for await (const batch of transcribeService.batchTranscribeFiles(files)) {
     164                    for (const t of batch) {
     165                        if (!t.success) {
     166                            createFailure(this, t);
     167                        }
     168                        else {
     169                            const f = files.find(f => f.name === t.file_name);
     170                            if (f === undefined) {
     171                                createFailure(this, t, this.translations.get("ErrorTryAgain"));
     172                            }
     173
     174                            const tvm = new TranscriptionViewModel(t, f);
     175
     176                            try {
     177                                this.$store.commit("transcriptionAdd", tvm);
     178                            }
     179                            catch (TranscriptionExistsError) {
     180                                createFailure(this, t, this.translations.get("AudioUpload_AlreadyTranscribed"));
     181                            }
     182                        }
     183                    }
     184                }
     185            }
     186            catch (e) {
     187                console.error("Failed to transcribe files");
     188                console.error(e);
     189
     190                const failure = new TranscriptionViewFailure(e.fileName, e.message);
     191                this.failures.set(failure.id, failure);
     192            }
     193
     194            function createFailure(that, t, reason = null) {
     195                const failure = new TranscriptionViewFailure(t.file_name, reason ?? t.log);
     196                that.failures.set(failure.id, failure);
     197            }
    154198        }
    155199    }
    156200}
    157 
    158 /**
    159  * Gets the transcription of each submitted audio file.
    160  *
    161  * @param {File[]} files The files to transcribe.
    162  */
    163 async function getTranscriptions(files, store, vm) {
    164     await Util.delay(200); // TODO: Remove - UI testing purposes only
    165 
    166     try {
    167         for await (const batch of transcribeService.batchTranscribeFiles(files)) {
    168             for (const t of batch) {
    169                 if (!t.success) {
    170                     const failure = new TranscriptionViewFailure(t.file_name, t.log);
    171                     vm.failures.set(failure.id, failure);
    172                 }
    173                 else {
    174                     const f = files.find(f => f.name === t.file_name);
    175                     if (f === undefined) {
    176                         throw new Error("File name mismatch");
    177                     }
    178 
    179                     // TODO: Hash file name and size instead. Good indicator that the user has uploaded a duplicate.
    180                     const tvm = new TranscriptionViewModel(t, f);
    181                     store.commit("transcriptionAdd", tvm);
    182                     // let model = new TranscriptionViewModel(t, f);
    183                     // model.words = getTranscriptionWords(t);
    184 
    185                     // TranscriptionsListVM.transcriptions.set(model.id, model);
    186                 }
    187             }
    188         }
    189     }
    190     catch (e) {
    191         console.error("Failed to transcribe files");
    192         console.error(e);
    193 
    194         const failure = new TranscriptionViewFailure(e.fileName, e.message);
    195         vm.failures.set(failure.id, failure);
    196     }
    197 }
    198201</script>
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/ToggleButton.vue

    r35431 r35432  
    1010    color: var(--primary-bg-color);
    1111    background-color: var(--paper-color);
    12     border: 2px solid var(--primary-bg-color);
    1312    box-shadow: var(--primary-box-shadow-thin);
    1413}
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/main.js

    r35430 r35432  
    33import App from "./App.vue";
    44import ToggleButton from "./components/ToggleButton.vue"
    5 import Util from "./js/Util"
    65
    76export class TranscriptionViewModel {
     
    1413    constructor(transcription, file) {
    1514        /** @type {String} The UUID of this transcription. */
    16         this.id = Util.generateUuid();
     15        this.id = file.name + file.size + file.type; // Should be a fairly reliable indicator of uniqueness.
    1716
    1817        /** @type {String} The transcription. */
     
    5352}
    5453
     54export class TranscriptionExistsError extends Error {
     55    constructor(message = "", ...args) {
     56        super(message, ...args);
     57    }
     58}
     59
    5560const store = createStore({
    5661    state() {
     
    7075         */
    7176        transcriptionAdd(state, transcription) {
     77            if (state.rawTranscriptions.has(transcription.id)) {
     78                throw new Error("Transcription already exists");
     79            }
    7280            state.rawTranscriptions.set(transcription.id, transcription);
    7381        },
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/styles/_material.scss

    r35431 r35432  
    2121    --body-color: rgb(39, 39, 39);
    2222   
    23     --primary-box-shadow: 0px 2px 4px 0px #505050;
    24     --primary-box-shadow-thin: 0px 1px 3px 0px #747474;
     23    --primary-box-shadow: 0 2px 4px 0 #505050;
     24    --primary-box-shadow-thin: 0 1px 3px 0 #747474;
     25
    2526    --hover-brightness: 92%;
    2627
     
    5051    --primary-bg-color: var(--accent-bg-color);
    5152    --primary-fg-color: var(--accent-fg-color);
    52 }
    53 
    54 .border-accent {
    55     border: 2px var(--accent-bg-color) solid;
    5653}
    5754
     
    248245    width: 100%; // Required for firefox
    249246
    250     &:focus {
    251         outline: none;
    252     }
    253 
    254247    &::-webkit-slider-thumb {
    255248        -webkit-appearance: none;
Note: See TracChangeset for help on using the changeset viewer.