Skip to content

Commit

Permalink
add ability to cancel a scheduled transcription
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
  • Loading branch information
julien-nc committed Feb 27, 2024
1 parent 5993a42 commit 3e4fa22
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/private/SpeechToText/SpeechToTextManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@ public function scheduleFileTranscription(File $file, ?string $userId, string $a
}
}

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');
Expand Down
11 changes: 11 additions & 0 deletions lib/public/SpeechToText/ISpeechToTextManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ public function getProviders(): array;
*/
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
Expand Down

0 comments on commit 3e4fa22

Please sign in to comment.