diff options
Diffstat (limited to 'lib/public/SpeechToText')
7 files changed, 283 insertions, 0 deletions
diff --git a/lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php b/lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php new file mode 100644 index 00000000000..6554292d413 --- /dev/null +++ b/lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php @@ -0,0 +1,58 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\SpeechToText\Events; + +use OCP\EventDispatcher\Event; +use OCP\Files\File; + +/** + * @since 27.0.0 + * @deprecated 30.0.0 + */ +abstract class AbstractTranscriptionEvent extends Event { + /** + * @since 27.0.0 + */ + public function __construct( + private int $fileIdId, + private ?File $file, + private ?string $userId, + private string $appId, + ) { + parent::__construct(); + } + + /** + * @since 27.0.0 + */ + public function getFileId(): int { + return $this->fileIdId; + } + + /** + * @since 27.0.0 + */ + public function getFile(): ?File { + return $this->file; + } + + /** + * @since 27.0.0 + */ + public function getUserId(): ?string { + return $this->userId; + } + + /** + * @since 27.0.0 + */ + public function getAppId(): string { + return $this->appId; + } +} diff --git a/lib/public/SpeechToText/Events/TranscriptionFailedEvent.php b/lib/public/SpeechToText/Events/TranscriptionFailedEvent.php new file mode 100644 index 00000000000..4c2b0d52017 --- /dev/null +++ b/lib/public/SpeechToText/Events/TranscriptionFailedEvent.php @@ -0,0 +1,41 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + + +namespace OCP\SpeechToText\Events; + +use OCP\Files\File; + +/** + * This Event is emitted if a transcription of a media file using a Speech-To-Text provider failed + * @since 27.0.0 + * @deprecated 30.0.0 + */ +class TranscriptionFailedEvent extends AbstractTranscriptionEvent { + /** + * @since 27.0.0 + */ + public function __construct( + int $fileId, + ?File $file, + private string $errorMessage, + ?string $userId, + string $appId, + ) { + parent::__construct($fileId, $file, $userId, $appId); + } + + /** + * @since 27.0.0 + * @return string The error message + */ + public function getErrorMessage(): string { + return $this->errorMessage; + } +} diff --git a/lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php b/lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php new file mode 100644 index 00000000000..e8e5359a29e --- /dev/null +++ b/lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php @@ -0,0 +1,41 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + + +namespace OCP\SpeechToText\Events; + +use OCP\Files\File; + +/** + * This Event is emitted when a transcription of a media file happened successfully + * @since 27.0.0 + * @deprecated 30.0.0 + */ +class TranscriptionSuccessfulEvent extends AbstractTranscriptionEvent { + /** + * @since 27.0.0 + */ + public function __construct( + int $fileId, + ?File $file, + private string $transcript, + ?string $userId, + string $appId, + ) { + parent::__construct($fileId, $file, $userId, $appId); + } + + /** + * @since 27.0.0 + * @return string The transcript of the media file + */ + public function getTranscript(): string { + return $this->transcript; + } +} diff --git a/lib/public/SpeechToText/ISpeechToTextManager.php b/lib/public/SpeechToText/ISpeechToTextManager.php new file mode 100644 index 00000000000..6bd95197695 --- /dev/null +++ b/lib/public/SpeechToText/ISpeechToTextManager.php @@ -0,0 +1,71 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + + +namespace OCP\SpeechToText; + +use InvalidArgumentException; +use OCP\Files\File; +use OCP\PreConditionNotMetException; +use RuntimeException; + +/** + * @since 27.0.0 + * @deprecated 30.0.0 + */ +interface ISpeechToTextManager { + /** + * @since 27.0.0 + */ + public function hasProviders(): bool; + + /** + * @return ISpeechToTextProvider[] + * @since 27.1.0 + */ + public function getProviders(): array; + + /** + * 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 + * belonging to your transcription request. + * + * @param File $file The media file to transcribe + * @param ?string $userId The user that triggered this request (only for convenience, will be available on the TranscriptEvents) + * @param string $appId The app that triggered this request (only for convenience, will be available on the TranscriptEvents) + * @throws PreConditionNotMetException If no provider was registered but this method was still called + * @throws InvalidArgumentException If the file could not be found or is not of a supported type + * @since 27.0.0 + */ + public function scheduleFileTranscription(File $file, ?string $userId, string $appId): void; + + /** + * Will cancel a scheduled transcription process + * + * @param File $file The media file involved in the transcription + * @param ?string $userId The user that triggered this request + * @param string $appId The app that triggered this request + * @throws InvalidArgumentException If the file could not be found or is not of a supported type + * @since 29.0.0 + */ + public function cancelScheduledFileTranscription(File $file, ?string $userId, string $appId): void; + + /** + * @param File $file The media file to transcribe + * @param ?string $userId The user that triggered this request + * @param string $appId The app that triggered this request + * @returns string The transcription of the passed media file + * @throws PreConditionNotMetException If no provider was registered but this method was still called + * @throws InvalidArgumentException If the file could not be found or is not of a supported type + * @throws RuntimeException If the transcription failed for other reasons + * @since 27.0.0 + */ + public function transcribeFile(File $file, ?string $userId, string $appId): string; +} diff --git a/lib/public/SpeechToText/ISpeechToTextProvider.php b/lib/public/SpeechToText/ISpeechToTextProvider.php new file mode 100644 index 00000000000..dce4a68ea0a --- /dev/null +++ b/lib/public/SpeechToText/ISpeechToTextProvider.php @@ -0,0 +1,31 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + + +namespace OCP\SpeechToText; + +use OCP\Files\File; +use RuntimeException; + +/** + * @since 27.0.0 + * @deprecated 30.0.0 + */ +interface ISpeechToTextProvider { + /** + * @since 27.0.0 + */ + public function getName(): string; + + /** + * @since 27.0.0 + * @throws RuntimeException If the text could not be transcribed + */ + public function transcribeFile(File $file): string; +} diff --git a/lib/public/SpeechToText/ISpeechToTextProviderWithId.php b/lib/public/SpeechToText/ISpeechToTextProviderWithId.php new file mode 100644 index 00000000000..8020c6c9b96 --- /dev/null +++ b/lib/public/SpeechToText/ISpeechToTextProviderWithId.php @@ -0,0 +1,19 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\SpeechToText; + +/** + * @since 28.0.0 + * @deprecated 30.0.0 + */ +interface ISpeechToTextProviderWithId extends ISpeechToTextProvider { + + /** + * @since 28.0.0 + */ + public function getId(): string; +} diff --git a/lib/public/SpeechToText/ISpeechToTextProviderWithUserId.php b/lib/public/SpeechToText/ISpeechToTextProviderWithUserId.php new file mode 100644 index 00000000000..d1bc4216a38 --- /dev/null +++ b/lib/public/SpeechToText/ISpeechToTextProviderWithUserId.php @@ -0,0 +1,22 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + + +namespace OCP\SpeechToText; + +/** + * @since 29.0.0 + * @deprecated 30.0.0 + */ +interface ISpeechToTextProviderWithUserId extends ISpeechToTextProvider { + /** + * @since 29.0.0 + */ + public function setUserId(?string $userId): void; +} |