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

Prevent duplicate transcriptions being created

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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>
Note: See TracChangeset for help on using the changeset viewer.