Skip to content

Commit

Permalink
fix(annotation): SRT converter combines same speaker units incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoemp committed Dec 9, 2024
1 parent 516adb6 commit 16806e1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
51 changes: 29 additions & 22 deletions libs/annotation/src/lib/converters/SRTConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions libs/annotation/src/lib/converters/TextConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
import {
AnyTextEditor,
BASWebservicesApplication,
OctraApplication, WordApplication
OctraApplication,
WordApplication,
} from './SupportedApplications';

// https://clarin.phonetik.uni-muenchen.de/BASWebServices/#/services/WebMAUSBasic
Expand All @@ -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'];
Expand Down

0 comments on commit 16806e1

Please sign in to comment.