diff --git a/developer_manual/digging_deeper/speech-to-text.rst b/developer_manual/digging_deeper/speech-to-text.rst index e2a3cb111..ceb157a02 100644 --- a/developer_manual/digging_deeper/speech-to-text.rst +++ b/developer_manual/digging_deeper/speech-to-text.rst @@ -109,6 +109,51 @@ The method ``transcribeFile`` transcribes the passed file and returns the transc The class would typically be saved into a file in ``lib/SpeechToText`` of your app but you are free to put it elsewhere as long as it's loadable by Nextcloud's :ref:`dependency injection container`. +Provider with user context +-------------------------- + +.. versionadded:: 29.0.0 + +Sometimes the processing of a the task may depend upon which user requested the task. +You can now obtain this information in your provider by additionally implementing the ``OCP\SpeechToText\ISpeechToTextProviderWithUserId`` interface: + +.. code-block:: php + :emphasize-lines: 9,12,14,25,26,27 + + l->t('My awesome speech to text provider'); + } + + public function setUserId(?string $userId): void { + $this->userId = $userId; + } + + public function transcribeFile(File $file): string { + // transcribe file here with the use of $this->userId context and return transcript + } + } + + Provider registration --------------------- diff --git a/developer_manual/digging_deeper/translation.rst b/developer_manual/digging_deeper/translation.rst index 1d17b0a29..ae85de54e 100644 --- a/developer_manual/digging_deeper/translation.rst +++ b/developer_manual/digging_deeper/translation.rst @@ -64,6 +64,55 @@ The method ``translate`` translates the passed string and returns the translatio The class would typically be saved into a file in ``lib/Translation`` of your app but you are free to put it elsewhere as long as it's loadable by Nextcloud's :ref:`dependency injection container`. +Provider with user context +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. versionadded:: 29.0.0 + +Sometimes the processing of a the task may depend upon which user requested the task. +You can now obtain this information in your provider by additionally implementing the ``OCP\Translation\ITranslationProviderWithUserId`` interface: + +.. code-block:: php + :emphasize-lines: 9,12,14,29,30,31 + + l->t('My awesome translation provider'); + } + + public function getAvailableLanguages(): array { + // Return an array of OCP\Translation\LanguageTuple objects here + } + + public function setUserId(?string $userId): void { + $this->userId = $userId; + } + + public function translate(?string $fromLanguage, string $toLanguage, string $text): string { + // Do some fancy machine translation and return translated string + } + } + + Providing language detection ^^^^^^^^^^^^^^^^^^^^^^^^^^^^