Adds tests for whisperx

This commit is contained in:
Guillaume Tâche
2024-09-16 17:41:58 +02:00
parent 3cc2f7a0c9
commit 233b4bdb77
16 changed files with 817 additions and 3 deletions

View File

@@ -54,7 +54,7 @@ public class WhisperXSetupManager extends AbstractWhisperSetupManager {
@Override
protected boolean isWhisperInstalled() throws SetupException {
final var path = getPythonPath();
if (Files.exists(path)) {
if (Files.isRegularFile(path)) {
try {
final var result = processRunner().run(List.of(path.toString(), "-m", "pip", "show", "whisperx"), Duration.ofSeconds(5));
return result.exitCode() == 0;

View File

@@ -29,7 +29,7 @@ public class WhisperXSubtitleExtractor extends AbstractWhisperSubtitleExtractor
@Override
protected List<String> createArgs(final Path path, final Language language, final ExtractionModel model, final Path outputDir) {
final var args = new ArrayList<String>(14);
final var args = new ArrayList<String>();
args.add(getPythonPath().toString());
args.add("-m");
args.add("whisperx");

View File

@@ -70,7 +70,7 @@ public class JSONSubtitleConverter implements SubtitleConverter<SubtitleImpl> {
}
}).sorted(Comparator.comparing(Subtitle::start).thenComparing(Subtitle::end)).toList();
final var language = Language.getLanguage(json.language());
final var subtitlesText = subtitles.stream().map(Subtitle::content).collect(Collectors.joining(""));
final var subtitlesText = subtitles.stream().map(s -> s.content().trim()).collect(Collectors.joining(" "));
return new SubtitleCollectionImpl<>(subtitlesText, subtitles, language);
} catch (final Exception e) {
throw new ParseException(e);
@@ -101,6 +101,8 @@ public class JSONSubtitleConverter implements SubtitleConverter<SubtitleImpl> {
final var newLength = builder.length() + s.length();
if (areDifferentLines(builder.length(), newLength, maxLineLength)) {
builder.append("\n").append(s);
} else if (builder.isEmpty()) {
builder.append(s);
} else {
builder.append(" ").append(s);
}
@@ -138,6 +140,8 @@ public class JSONSubtitleConverter implements SubtitleConverter<SubtitleImpl> {
currentStart = start == 0 ? currentEnd : start;
} else if (areDifferentLines(builder.length(), newLength, maxLineLength)) {
builder.append("\n").append(text);
} else if (builder.isEmpty()) {
builder.append(text);
} else {
builder.append(" ").append(text);
}