diff --git a/config/default.yaml b/config/default.yaml index c6512ca804f..80a485cb48b 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -806,6 +806,11 @@ video_transcription: # At least 1 remote runner must be configured to transcribe your videos remote_runners: enabled: false + + # Size of transcription files to keep on your server + # If the transcription file is smaller than this size, PeerTube will delete it after transcription + # With this setting, you can limit the hallucinations of the transcription engine + limit_valid_transcription_size: 100 video_file: update: diff --git a/server/core/initializers/config.ts b/server/core/initializers/config.ts index 878ffeb8d3b..c79afcf1c54 100644 --- a/server/core/initializers/config.ts +++ b/server/core/initializers/config.ts @@ -750,6 +750,9 @@ const CONFIG = { get MODEL_PATH () { return config.get('video_transcription.model_path') }, + get LIMIT_VALID_TRANSCRIPTION_SIZE () { + return config.get('video_transcription.limit_valid_transcription_size') + }, REMOTE_RUNNERS: { get ENABLED () { return config.get('video_transcription.remote_runners.enabled') diff --git a/server/core/lib/video-captions.ts b/server/core/lib/video-captions.ts index d885dc2f54f..1b15837a717 100644 --- a/server/core/lib/video-captions.ts +++ b/server/core/lib/video-captions.ts @@ -23,6 +23,7 @@ import { JobQueue } from './job-queue/job-queue.js' import { Notifier } from './notifier/notifier.js' import { TranscriptionJobHandler } from './runners/index.js' import { VideoPathManager } from './video-path-manager.js' +import { promises as fs } from 'fs' const lTags = loggerTagsFactory('video-caption') @@ -213,6 +214,18 @@ export async function onTranscriptionEnded (options: { lTags?: (string | number)[] }) { const { video, language, vttPath, lTags: customLTags = [] } = options + var limitValideTranscriptionSize = CONFIG.VIDEO_TRANSCRIPTION.LIMIT_VALID_TRANSCRIPTION_SIZE || 100 + + try { + const stats = await fs.stat(vttPath) + if (stats.size < limitValideTranscriptionSize) { + logger.info(`Transcription file ${vttPath} is too small, do not create caption for video ${video.uuid}`) + return + } + } catch (err) { + logger.error(`Error while checking transcription file ${vttPath} for video ${video.uuid}`, { err }) + return + } if (!isVideoCaptionLanguageValid(language)) { logger.warn(`Invalid transcription language for video ${video.uuid}`, lTags(video.uuid))