]> source.dussan.org Git - nextcloud-server.git/commitdiff
ISpeechToTextProvider#transcribeFile: Pass \OCP\Files\File instead of path
authorMarcel Klehr <mklehr@gmx.net>
Wed, 12 Apr 2023 14:52:11 +0000 (16:52 +0200)
committerMarcel Klehr <mklehr@gmx.net>
Wed, 12 Apr 2023 14:52:11 +0000 (16:52 +0200)
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
lib/private/SpeechToText/SpeechToTextManager.php
lib/public/SpeechToText/ISpeechToTextManager.php
lib/public/SpeechToText/ISpeechToTextProvider.php

index 2e1733d0e3673d9f5764c5bbf2e6df653dd8ea88..7b50fa385c98f4e63f5b51609877c5144b32a66a 100644 (file)
@@ -31,6 +31,9 @@ namespace OC\SpeechToText;
 use InvalidArgumentException;
 use OC\AppFramework\Bootstrap\Coordinator;
 use OCP\BackgroundJob\IJobList;
+use OCP\Files\File;
+use OCP\Files\IRootFolder;
+use OCP\Files\NotFoundException;
 use OCP\IServerContainer;
 use OCP\PreConditionNotMetException;
 use OCP\SpeechToText\ISpeechToTextManager;
@@ -49,6 +52,7 @@ class SpeechToTextManager implements ISpeechToTextManager {
                private Coordinator $coordinator,
                private LoggerInterface $logger,
                private IJobList $jobList,
+               private IRootFolder $rootFolder,
        ) {
        }
 
@@ -90,6 +94,14 @@ class SpeechToTextManager implements ISpeechToTextManager {
                if (!$this->hasProviders()) {
                        throw new PreConditionNotMetException('No SpeechToText providers have been registered');
                }
+               try {
+                       $node = $this->rootFolder->get($path);
+               } catch (NotFoundException $e) {
+                       throw new InvalidArgumentException('File does not exist: ' . $path);
+               }
+               if (!($node instanceof File)) {
+                       throw new InvalidArgumentException('Path does not resolve to a file');
+               }
                $this->jobList->add(TranscriptionJob::class, [ 'path' => $path, 'context' => $context]);
        }
 
@@ -99,10 +111,14 @@ class SpeechToTextManager implements ISpeechToTextManager {
                        throw new PreConditionNotMetException('No SpeechToText providers have been registered');
                }
 
-               if (!file_exists($path)) {
-                       throw new InvalidArgumentException('File does not exist');
+               try {
+                       $node = $this->rootFolder->get($path);
+                       if (!($node instanceof File)) {
+                               throw new InvalidArgumentException('Path does not resolve to a file');
+                       }
+                       return $provider->transcribeFile($node);
+               } catch (NotFoundException $e) {
+                       throw new InvalidArgumentException('File does not exist: ' . $path);
                }
-
-               return $provider->transcribeFile($path);
        }
 }
index 297be43e6db9d82851150546993abc7588dd9c4d..7bcd60bce8c0ee74afa234f81df8f5d09b17eb31 100644 (file)
@@ -43,7 +43,7 @@ interface ISpeechToTextManager {
         * Will schedule a transcription process in the background. The result will become available
         * with the \OCP\SpeechToText\Events\TranscriptionFinishedEvent
         * You should add context information to the context array to re-identify the transcription result as
-        * as belonging to your transcription request.
+        * belonging to your transcription request.
         *
         * @since 27.0.0
         * @throws PreConditionNotMetException If no provider was registered but this method was still called
index 3d739408bf5d49d1bda40e5e74675098e45d5d1d..c23b75c115ea4489cbf6db8be7a23527d73e59b9 100644 (file)
@@ -26,6 +26,7 @@ declare(strict_types=1);
 
 namespace OCP\SpeechToText;
 
+use OCP\Files\File;
 use RuntimeException;
 
 /**
@@ -41,5 +42,5 @@ interface ISpeechToTextProvider {
         * @since 27.0.0
         * @throws RuntimeException If the text could not be transcribed
         */
-       public function transcribeFile(string $path): string;
+       public function transcribeFile(File $file): string;
 }