Skip to content

Commit 1c5411e

Browse files
committed
enh(SpeechToText): Allow providers to declare a dynamic ID instead of using className
this allows AppAPI to register anonymous classes as SpeechToText providers Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 7a55ea7 commit 1c5411e

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

apps/settings/lib/Settings/Admin/ArtificialIntelligence.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use OCP\IL10N;
3232
use OCP\Settings\IDelegatedSettings;
3333
use OCP\SpeechToText\ISpeechToTextManager;
34+
use OCP\SpeechToText\ISpeechToTextProviderWithId;
3435
use OCP\TextProcessing\IManager;
3536
use OCP\TextProcessing\IProvider;
3637
use OCP\TextProcessing\ITaskType;
@@ -68,7 +69,7 @@ public function getForm() {
6869
$sttProviders = [];
6970
foreach ($this->sttManager->getProviders() as $provider) {
7071
$sttProviders[] = [
71-
'class' => $provider::class,
72+
'class' => $provider instanceof ISpeechToTextProviderWithId ? $provider->getId() : $provider::class,
7273
'name' => $provider->getName(),
7374
];
7475
}

lib/private/SpeechToText/SpeechToTextManager.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use OCP\PreConditionNotMetException;
4040
use OCP\SpeechToText\ISpeechToTextManager;
4141
use OCP\SpeechToText\ISpeechToTextProvider;
42+
use OCP\SpeechToText\ISpeechToTextProviderWithId;
4243
use Psr\Container\ContainerExceptionInterface;
4344
use Psr\Container\NotFoundExceptionInterface;
4445
use Psr\Log\LoggerInterface;
@@ -117,8 +118,13 @@ public function transcribeFile(File $file): string {
117118

118119
$json = $this->config->getAppValue('core', 'ai.stt_provider', '');
119120
if ($json !== '') {
120-
$className = json_decode($json, true);
121-
$provider = current(array_filter($providers, fn ($provider) => $provider::class === $className));
121+
$classNameOrId = json_decode($json, true);
122+
$provider = current(array_filter($providers, function ($provider) use ($classNameOrId) {
123+
if ($provider instanceof ISpeechToTextProviderWithId) {
124+
return $provider->getId() === $classNameOrId;
125+
}
126+
return $provider::class === $classNameOrId;
127+
}));
122128
if ($provider !== false) {
123129
$providers = [$provider];
124130
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace OCP\SpeechToText;
4+
5+
/**
6+
* @since 28.0.0
7+
*/
8+
interface ISpeechToTextProviderWithId extends ISpeechToTextProvider {
9+
10+
/**
11+
* @since 28.0.0
12+
*/
13+
public function getId(): string;
14+
}

0 commit comments

Comments
 (0)