Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to cancel a scheduled transcription #43862

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading