diff options
author | Marcel Klehr <mklehr@gmx.net> | 2023-04-13 12:12:07 +0200 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2023-04-13 12:12:07 +0200 |
commit | a8d3fff648c4c6f5be3e37c09f9168e5b7c0e8f8 (patch) | |
tree | 6115b6748d00997155016d708879e796bfe21344 /lib/private/SpeechToText | |
parent | 176f1af26a6bf7c62cadd04448b73839296653c0 (diff) | |
download | nextcloud-server-a8d3fff648c4c6f5be3e37c09f9168e5b7c0e8f8.tar.gz nextcloud-server-a8d3fff648c4c6f5be3e37c09f9168e5b7c0e8f8.zip |
Split TranscriptionFinishedEvent into Successful and Failed events
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib/private/SpeechToText')
-rw-r--r-- | lib/private/SpeechToText/SpeechToTextManager.php | 5 | ||||
-rw-r--r-- | lib/private/SpeechToText/TranscriptionJob.php | 28 |
2 files changed, 20 insertions, 13 deletions
diff --git a/lib/private/SpeechToText/SpeechToTextManager.php b/lib/private/SpeechToText/SpeechToTextManager.php index a734f6bb379..c4f89ed43c7 100644 --- a/lib/private/SpeechToText/SpeechToTextManager.php +++ b/lib/private/SpeechToText/SpeechToTextManager.php @@ -33,7 +33,6 @@ use OC\AppFramework\Bootstrap\Coordinator; use OCP\BackgroundJob\IJobList; use OCP\Files\File; use OCP\Files\InvalidPathException; -use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\IServerContainer; use OCP\PreConditionNotMetException; @@ -96,7 +95,7 @@ class SpeechToTextManager implements ISpeechToTextManager { } try { $this->jobList->add(TranscriptionJob::class, ['fileId' => $file->getId()]); - }catch(NotFoundException|InvalidPathException $e) { + } catch (NotFoundException|InvalidPathException $e) { throw new InvalidArgumentException('Invalid file provided for file transcription: ' . $e->getMessage()); } } @@ -109,7 +108,7 @@ class SpeechToTextManager implements ISpeechToTextManager { try { return $provider->transcribeFile($file); - }catch (\Throwable $e) { + } catch (\Throwable $e) { $this->logger->info('SpeechToText transcription failed', ['exception' => $e]); throw new \RuntimeException('SpeechToText transcription failed: ' . $e->getMessage()); } diff --git a/lib/private/SpeechToText/TranscriptionJob.php b/lib/private/SpeechToText/TranscriptionJob.php index 296a713593b..775a2a7fadc 100644 --- a/lib/private/SpeechToText/TranscriptionJob.php +++ b/lib/private/SpeechToText/TranscriptionJob.php @@ -5,9 +5,11 @@ namespace OC\SpeechToText; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\QueuedJob; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\File; use OCP\Files\IRootFolder; use OCP\PreConditionNotMetException; -use OCP\SpeechToText\Events\TranscriptionFinishedEvent; +use OCP\SpeechToText\Events\TranscriptionFailedEvent; +use OCP\SpeechToText\Events\TranscriptionSuccessfulEvent; use OCP\SpeechToText\ISpeechToTextManager; class TranscriptionJob extends QueuedJob { @@ -25,24 +27,30 @@ class TranscriptionJob extends QueuedJob { * @inheritDoc */ protected function run($argument) { + $fileId = $argument['fileId']; try { - $file = $this->rootFolder->getById($argument['fileId']); + $file = current($this->rootFolder->getById($fileId)); + if (!($file instanceof File)) { + $this->eventDispatcher->dispatchTyped( + new TranscriptionFailedEvent( + $fileId, + 'File not found', + ) + ); + return; + } $result = $this->speechToTextManager->transcribeFile($file); $this->eventDispatcher->dispatchTyped( - new TranscriptionFinishedEvent( - true, + new TranscriptionSuccessfulEvent( + $fileId, $result, - '', - $argument['context'] ) ); } catch (PreConditionNotMetException|\RuntimeException|\InvalidArgumentException $e) { $this->eventDispatcher->dispatchTyped( - new TranscriptionFinishedEvent( - false, - '', + new TranscriptionFailedEvent( + $fileId, $e->getMessage(), - $argument['context'] ) ); } |