Skip to content

Commit 023386b

Browse files
andrey18106acataluddi
authored andcommitted
Speech-To-Text and Machine Translation providers with user context (nextcloud#11536)
Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com> Signed-off-by: Adriano Cataluddi <acataluddi@gmail.com>
1 parent 36ed3bf commit 023386b

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

developer_manual/digging_deeper/speech-to-text.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,51 @@ The method ``transcribeFile`` transcribes the passed file and returns the transc
109109

110110
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<dependency-injection>`.
111111

112+
Provider with user context
113+
--------------------------
114+
115+
.. versionadded:: 29.0.0
116+
117+
Sometimes the processing of a the task may depend upon which user requested the task.
118+
You can now obtain this information in your provider by additionally implementing the ``OCP\SpeechToText\ISpeechToTextProviderWithUserId`` interface:
119+
120+
.. code-block:: php
121+
:emphasize-lines: 9,12,14,25,26,27
122+
123+
<?php
124+
125+
declare(strict_types=1);
126+
127+
namespace OCA\MyApp\SpeechToText;
128+
129+
use OCA\MyApp\AppInfo\Application;
130+
use OCP\Files\File;
131+
use OCP\SpeechToText\ISpeechToTextProviderWithUserId;
132+
use OCP\IL10N;
133+
134+
class Provider implements ISpeechToTextProviderWithUserId {
135+
136+
private ?string $userId = null;
137+
138+
public function __construct(
139+
private IL10N $l,
140+
) {
141+
}
142+
143+
public function getName(): string {
144+
return $this->l->t('My awesome speech to text provider');
145+
}
146+
147+
public function setUserId(?string $userId): void {
148+
$this->userId = $userId;
149+
}
150+
151+
public function transcribeFile(File $file): string {
152+
// transcribe file here with the use of $this->userId context and return transcript
153+
}
154+
}
155+
156+
112157
Provider registration
113158
---------------------
114159

developer_manual/digging_deeper/translation.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,55 @@ The method ``translate`` translates the passed string and returns the translatio
6464

6565
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<dependency-injection>`.
6666

67+
Provider with user context
68+
^^^^^^^^^^^^^^^^^^^^^^^^^^
69+
70+
.. versionadded:: 29.0.0
71+
72+
Sometimes the processing of a the task may depend upon which user requested the task.
73+
You can now obtain this information in your provider by additionally implementing the ``OCP\Translation\ITranslationProviderWithUserId`` interface:
74+
75+
.. code-block:: php
76+
:emphasize-lines: 9,12,14,29,30,31
77+
78+
<?php
79+
80+
declare(strict_types=1);
81+
82+
namespace OCA\MyApp\Translation;
83+
84+
use OCA\MyApp\AppInfo\Application;
85+
use OCP\Files\File;
86+
use OCP\Translation\ITranslationProviderWithUserId;
87+
use OCP\IL10N;
88+
89+
class Provider implements ITranslationProviderWithUserId {
90+
91+
private ?string $userId = null;
92+
93+
public function __construct(
94+
private IL10N $l,
95+
) {
96+
}
97+
98+
public function getName(): string {
99+
return $this->l->t('My awesome translation provider');
100+
}
101+
102+
public function getAvailableLanguages(): array {
103+
// Return an array of OCP\Translation\LanguageTuple objects here
104+
}
105+
106+
public function setUserId(?string $userId): void {
107+
$this->userId = $userId;
108+
}
109+
110+
public function translate(?string $fromLanguage, string $toLanguage, string $text): string {
111+
// Do some fancy machine translation and return translated string
112+
}
113+
}
114+
115+
67116
Providing language detection
68117
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
69118

0 commit comments

Comments
 (0)