diff --git a/lib/private/SpeechToText/SpeechToTextManager.php b/lib/private/SpeechToText/SpeechToTextManager.php index 73efe105b38..10944a0b424 100644 --- a/lib/private/SpeechToText/SpeechToTextManager.php +++ b/lib/private/SpeechToText/SpeechToTextManager.php @@ -112,6 +112,24 @@ class SpeechToTextManager implements ISpeechToTextManager { } } + public function cancelScheduledFileTranscription(File $file, ?string $userId, string $appId): void { + try { + $jobArguments = [ + 'fileId' => $file->getId(), + 'owner' => $file->getOwner()->getUID(), + 'userId' => $userId, + 'appId' => $appId, + ]; + if (!$this->jobList->has(TranscriptionJob::class, $jobArguments)) { + $this->logger->debug('Failed to cancel a Speech-to-text job for file ' . $file->getId() . '. No related job was found.'); + return; + } + $this->jobList->remove(TranscriptionJob::class, $jobArguments); + } catch (NotFoundException|InvalidPathException $e) { + throw new InvalidArgumentException('Invalid file provided to cancel file transcription: ' . $e->getMessage()); + } + } + public function transcribeFile(File $file): string { if (!$this->hasProviders()) { throw new PreConditionNotMetException('No SpeechToText providers have been registered'); diff --git a/lib/public/SpeechToText/ISpeechToTextManager.php b/lib/public/SpeechToText/ISpeechToTextManager.php index 96973cfca08..f281d52f0dd 100644 --- a/lib/public/SpeechToText/ISpeechToTextManager.php +++ b/lib/public/SpeechToText/ISpeechToTextManager.php @@ -61,6 +61,17 @@ interface ISpeechToTextManager { */ public function scheduleFileTranscription(File $file, ?string $userId, string $appId): void; + /** + * Will cancel a scheduled transcription process + * + * @param File $file The media file involved in the transcription + * @param ?string $userId The user that triggered this request + * @param string $appId The app that triggered this request + * @throws InvalidArgumentException If the file could not be found or is not of a supported type + * @since 29.0.0 + */ + public function cancelScheduledFileTranscription(File $file, ?string $userId, string $appId): void; + /** * @param File $file The media file to transcribe * @returns string The transcription of the passed media file