diff options
author | Marcel Klehr <mklehr@gmx.net> | 2023-04-11 14:59:57 +0200 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2023-04-11 14:59:57 +0200 |
commit | 317521b607e3a14364f5d486630cf1e5181053e4 (patch) | |
tree | 17fa3479a7169e92739232fb7c594c7f9e3cce56 /lib/private/SpeechToText/TranscriptionJob.php | |
parent | c6645cbc46291d2621992b7f0bb087f115e849eb (diff) | |
download | nextcloud-server-317521b607e3a14364f5d486630cf1e5181053e4.tar.gz nextcloud-server-317521b607e3a14364f5d486630cf1e5181053e4.zip |
feat(SpeechToText): Add SpeechToText provider API
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib/private/SpeechToText/TranscriptionJob.php')
-rw-r--r-- | lib/private/SpeechToText/TranscriptionJob.php | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/private/SpeechToText/TranscriptionJob.php b/lib/private/SpeechToText/TranscriptionJob.php new file mode 100644 index 00000000000..d2cff468024 --- /dev/null +++ b/lib/private/SpeechToText/TranscriptionJob.php @@ -0,0 +1,47 @@ +<?php + +namespace OC\SpeechToText; + +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\QueuedJob; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\PreConditionNotMetException; +use OCP\SpeechToText\Events\TranscriptionFinishedEvent; +use OCP\SpeechToText\ISpeechToTextManager; + +class TranscriptionJob extends QueuedJob { + public function __construct( + ITimeFactory $timeFactory, + private ISpeechToTextManager $speechToTextManager, + private IEventDispatcher $eventDispatcher, + ) { + parent::__construct($timeFactory); + } + + + /** + * @inheritDoc + */ + protected function run($argument) { + try { + $result = $this->speechToTextManager->transcribeFile($argument['path']); + $this->eventDispatcher->dispatchTyped( + new TranscriptionFinishedEvent( + true, + $result, + '', + $argument['context'] + ) + ); + } catch (PreConditionNotMetException|\RuntimeException|\InvalidArgumentException $e) { + $this->eventDispatcher->dispatchTyped( + new TranscriptionFinishedEvent( + false, + '', + $e->getMessage(), + $argument['context'] + ) + ); + } + } +} |