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;
private Coordinator $coordinator,
private LoggerInterface $logger,
private IJobList $jobList,
+ private IRootFolder $rootFolder,
) {
}
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]);
}
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);
}
}
* 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