diff --git a/libs/annotation/src/lib/converters/SRTConverter.ts b/libs/annotation/src/lib/converters/SRTConverter.ts index 7eec14e13..c967dc112 100644 --- a/libs/annotation/src/lib/converters/SRTConverter.ts +++ b/libs/annotation/src/lib/converters/SRTConverter.ts @@ -8,7 +8,12 @@ import { ImportResult, OctraAnnotationFormatType, } from './Converter'; -import { AnyTextEditor, AnyVideoPlayer, OctraApplication, WordApplication } from './SupportedApplications'; +import { + AnyTextEditor, + AnyVideoPlayer, + OctraApplication, + WordApplication, +} from './SupportedApplications'; export class SRTConverterImportOptions { sortSpeakerSegments = false; @@ -298,37 +303,39 @@ export class SRTConverter extends Converter { !text && duration <= options.combineSegmentsWithSameSpeakerThreshold ) { - // remove segment + // current unit is empty, previous and next is set + // remove empty unit defaultLevel.items.splice(i, 1); + // extend previousItem previousItem.sampleDur += item.sampleDur; - i--; + i--; // i = position of previous item if ( nextItem.labels[0].name === 'Speaker' && previousItem.labels[0].name === 'Speaker' && nextItem.labels[0].value === previousItem.labels[0].value ) { + // left and right neighbours have the same speaker + // remove nextItem defaultLevel.items.splice(i + 1, 1); - nextItem.sampleDur += item.sampleDur; - nextItem.sampleStart = item.sampleStart; - i--; - } - - const label = previousItem.getFirstLabelWithoutName('Speaker'); - if (label) { - const speakerRegex = - options.speakerIdentifierPattern && - options.speakerIdentifierPattern !== '' - ? options.speakerIdentifierPattern - : '\\[SPEAKER_[0-9]+] *: *'; - label.value += - nextItem.getFirstLabelWithoutName('Speaker')?.value ?? ''; - label.value = label.value.replace( - new RegExp(`(?!^) *${speakerRegex}`), - ' ' - ); + // extend previousItem + previousItem.sampleDur += nextItem.sampleDur; + + const label = previousItem.getFirstLabelWithoutName('Speaker'); + if (label) { + const speakerRegex = + options.speakerIdentifierPattern && + options.speakerIdentifierPattern !== '' + ? options.speakerIdentifierPattern + : '\\[SPEAKER_[0-9]+] *: *'; + label.value += + nextItem.getFirstLabelWithoutName('Speaker')?.value ?? ''; + label.value = label.value.replace( + new RegExp(`(?!^) *${speakerRegex}`), + ' ' + ); + } } - previousItem.sampleDur += nextItem.sampleDur; } } } diff --git a/libs/annotation/src/lib/converters/TextConverter.ts b/libs/annotation/src/lib/converters/TextConverter.ts index 99b4d9fae..29ff0f2b3 100644 --- a/libs/annotation/src/lib/converters/TextConverter.ts +++ b/libs/annotation/src/lib/converters/TextConverter.ts @@ -11,7 +11,8 @@ import { import { AnyTextEditor, BASWebservicesApplication, - OctraApplication, WordApplication + OctraApplication, + WordApplication, } from './SupportedApplications'; // https://clarin.phonetik.uni-muenchen.de/BASWebServices/#/services/WebMAUSBasic @@ -34,10 +35,10 @@ export class TextConverter extends Converter { application: new BASWebservicesApplication(), }, { - application: new AnyTextEditor(), + application: new WordApplication(), }, { - application: new WordApplication(), + application: new AnyTextEditor(), }, ]; this._extensions = ['.txt'];