diff options
Diffstat (limited to 'lib/private/SpeechToText/SpeechToTextManager.php')
-rw-r--r-- | lib/private/SpeechToText/SpeechToTextManager.php | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/lib/private/SpeechToText/SpeechToTextManager.php b/lib/private/SpeechToText/SpeechToTextManager.php index 10944a0b424..d69add2d80b 100644 --- a/lib/private/SpeechToText/SpeechToTextManager.php +++ b/lib/private/SpeechToText/SpeechToTextManager.php @@ -3,26 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net> - * @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net> - * - * @author Julius Härtl <jus@bitgrid.net> - * @author Marcel Klehr <mklehr@gmx.net> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -42,6 +24,9 @@ use OCP\SpeechToText\ISpeechToTextManager; use OCP\SpeechToText\ISpeechToTextProvider; use OCP\SpeechToText\ISpeechToTextProviderWithId; use OCP\SpeechToText\ISpeechToTextProviderWithUserId; +use OCP\TaskProcessing\IManager as ITaskProcessingManager; +use OCP\TaskProcessing\Task; +use OCP\TaskProcessing\TaskTypes\AudioToText; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Log\LoggerInterface; @@ -59,6 +44,7 @@ class SpeechToTextManager implements ISpeechToTextManager { private IJobList $jobList, private IConfig $config, private IUserSession $userSession, + private ITaskProcessingManager $taskProcessingManager, ) { } @@ -130,7 +116,30 @@ class SpeechToTextManager implements ISpeechToTextManager { } } - public function transcribeFile(File $file): string { + public function transcribeFile(File $file, ?string $userId = null, string $appId = 'core'): string { + // try to run a TaskProcessing core:audio2text task + // this covers scheduling as well because OC\SpeechToText\TranscriptionJob calls this method + try { + if (isset($this->taskProcessingManager->getAvailableTaskTypes()['core:audio2text'])) { + $taskProcessingTask = new Task( + AudioToText::ID, + ['input' => $file->getId()], + $appId, + $userId, + 'from-SpeechToTextManager||' . $file->getId() . '||' . ($userId ?? '') . '||' . $appId, + ); + $resultTask = $this->taskProcessingManager->runTask($taskProcessingTask); + if ($resultTask->getStatus() === Task::STATUS_SUCCESSFUL) { + $output = $resultTask->getOutput(); + if (isset($output['output']) && is_string($output['output'])) { + return $output['output']; + } + } + } + } catch (Throwable $e) { + throw new RuntimeException('Failed to run a Speech-to-text job from STTManager with TaskProcessing for file ' . $file->getId(), 0, $e); + } + if (!$this->hasProviders()) { throw new PreConditionNotMetException('No SpeechToText providers have been registered'); } |