SpeechToTextManager#scheduleFileTranscription: Take context params and expose them on the Transcription*Events

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
pull/37674/head
Marcel Klehr 3 years ago
parent a8b27c9126
commit a2f5421fc3
  1. 9
      lib/private/SpeechToText/SpeechToTextManager.php
  2. 8
      lib/private/SpeechToText/TranscriptionJob.php
  3. 16
      lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php
  4. 6
      lib/public/SpeechToText/Events/TranscriptionFailedEvent.php
  5. 6
      lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php
  6. 5
      lib/public/SpeechToText/ISpeechToTextManager.php

@ -90,12 +90,17 @@ class SpeechToTextManager implements ISpeechToTextManager {
return !empty($context->getSpeechToTextProviders());
}
public function scheduleFileTranscription(File $file): void {
public function scheduleFileTranscription(File $file, string $userId, string $appId): void {
if (!$this->hasProviders()) {
throw new PreConditionNotMetException('No SpeechToText providers have been registered');
}
try {
$this->jobList->add(TranscriptionJob::class, ['fileId' => $file->getId(), 'owner' => $file->getOwner()->getUID()]);
$this->jobList->add(TranscriptionJob::class, [
'fileId' => $file->getId(),
'owner' => $file->getOwner()->getUID(),
'userId' => $userId,
'appId' => $appId,
]);
} catch (NotFoundException|InvalidPathException $e) {
throw new InvalidArgumentException('Invalid file provided for file transcription: ' . $e->getMessage());
}

@ -58,6 +58,8 @@ class TranscriptionJob extends QueuedJob {
protected function run($argument) {
$fileId = $argument['fileId'];
$owner = $argument['owner'];
$userId = $argument['userId'];
$appId = $argument['appId'];
$file = null;
try {
\OC_Util::setupFS($owner);
@ -70,6 +72,8 @@ class TranscriptionJob extends QueuedJob {
$fileId,
null,
'File not found',
$userId,
$appId,
)
);
return;
@ -80,6 +84,8 @@ class TranscriptionJob extends QueuedJob {
$fileId,
$file,
$result,
$userId,
$appId,
)
);
} catch (PreConditionNotMetException|\RuntimeException|\InvalidArgumentException|NotFoundException|NotPermittedException|NoUserException $e) {
@ -89,6 +95,8 @@ class TranscriptionJob extends QueuedJob {
$fileId,
$file,
$e->getMessage(),
$userId,
$appId,
)
);
}

@ -38,6 +38,8 @@ abstract class AbstractTranscriptionEvent extends Event {
public function __construct(
private int $fileIdId,
private ?File $file,
private string $userId,
private string $appId,
) {
parent::__construct();
}
@ -55,4 +57,18 @@ abstract class AbstractTranscriptionEvent extends Event {
public function getFile(): ?File {
return $this->file;
}
/**
* @since 27.0.0
*/
public function getUserId(): string {
return $this->userId;
}
/**
* @since 27.0.0
*/
public function getAppId(): string {
return $this->appId;
}
}

@ -39,9 +39,11 @@ class TranscriptionFailedEvent extends AbstractTranscriptionEvent {
public function __construct(
int $fileId,
?File $file,
private string $errorMessage
private string $errorMessage,
string $userId,
string $appId,
) {
parent::__construct($fileId, $file);
parent::__construct($fileId, $file, $userId, $appId);
}
/**

@ -39,9 +39,11 @@ class TranscriptionSuccessfulEvent extends AbstractTranscriptionEvent {
public function __construct(
int $fileId,
?File $file,
private string $transcript
private string $transcript,
string $userId,
string $appId,
) {
parent::__construct($fileId, $file);
parent::__construct($fileId, $file, $userId, $appId);
}
/**

@ -46,11 +46,14 @@ interface ISpeechToTextManager {
* You should add context information to the context array to re-identify the transcription result as
* belonging to your transcription request.
*
* @param File $file The media file to transcribe
* @param string $userId The user that triggered this request (only for convenience, will be available on the TranscriptEvents)
* @param string $appId The app that triggered this request (only for convenience, will be available on the TranscriptEvents)
* @since 27.0.0
* @throws PreConditionNotMetException If no provider was registered but this method was still called
* @throws InvalidArgumentException If the file could not be found or is not of a supported type
*/
public function scheduleFileTranscription(File $file): void;
public function scheduleFileTranscription(File $file, string $userId, string $appId): void;
/**
* @since 27.0.0

Loading…
Cancel
Save