this allows AppAPI to register anonymous classes as SpeechToText providers Signed-off-by: Marcel Klehr <mklehr@gmx.net>tags/v29.0.0beta1
@@ -31,6 +31,7 @@ use OCP\IConfig; | |||
use OCP\IL10N; | |||
use OCP\Settings\IDelegatedSettings; | |||
use OCP\SpeechToText\ISpeechToTextManager; | |||
use OCP\SpeechToText\ISpeechToTextProviderWithId; | |||
use OCP\TextProcessing\IManager; | |||
use OCP\TextProcessing\IProvider; | |||
use OCP\TextProcessing\ITaskType; | |||
@@ -69,7 +70,7 @@ class ArtificialIntelligence implements IDelegatedSettings { | |||
$sttProviders = []; | |||
foreach ($this->sttManager->getProviders() as $provider) { | |||
$sttProviders[] = [ | |||
'class' => $provider::class, | |||
'class' => $provider instanceof ISpeechToTextProviderWithId ? $provider->getId() : $provider::class, | |||
'name' => $provider->getName(), | |||
]; | |||
} |
@@ -39,6 +39,7 @@ use OCP\IServerContainer; | |||
use OCP\PreConditionNotMetException; | |||
use OCP\SpeechToText\ISpeechToTextManager; | |||
use OCP\SpeechToText\ISpeechToTextProvider; | |||
use OCP\SpeechToText\ISpeechToTextProviderWithId; | |||
use Psr\Container\ContainerExceptionInterface; | |||
use Psr\Container\NotFoundExceptionInterface; | |||
use Psr\Log\LoggerInterface; | |||
@@ -117,8 +118,13 @@ class SpeechToTextManager implements ISpeechToTextManager { | |||
$json = $this->config->getAppValue('core', 'ai.stt_provider', ''); | |||
if ($json !== '') { | |||
$className = json_decode($json, true); | |||
$provider = current(array_filter($providers, fn ($provider) => $provider::class === $className)); | |||
$classNameOrId = json_decode($json, true); | |||
$provider = current(array_filter($providers, function ($provider) use ($classNameOrId) { | |||
if ($provider instanceof ISpeechToTextProviderWithId) { | |||
return $provider->getId() === $classNameOrId; | |||
} | |||
return $provider::class === $classNameOrId; | |||
})); | |||
if ($provider !== false) { | |||
$providers = [$provider]; | |||
} |
@@ -0,0 +1,14 @@ | |||
<?php | |||
namespace OCP\SpeechToText; | |||
/** | |||
* @since 28.0.0 | |||
*/ | |||
interface ISpeechToTextProviderWithId extends ISpeechToTextProvider { | |||
/** | |||
* @since 28.0.0 | |||
*/ | |||
public function getId(): string; | |||
} |