From 3f57725a7c68bd90b281a3f97639270cad25b072 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Mon, 17 Apr 2023 16:58:14 +0200 Subject: SpeechToTextManager#transcribeFile: Try next provider if one fails Signed-off-by: Marcel Klehr --- lib/private/SpeechToText/SpeechToTextManager.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/private/SpeechToText') diff --git a/lib/private/SpeechToText/SpeechToTextManager.php b/lib/private/SpeechToText/SpeechToTextManager.php index 0c41c3cb600..146d7f8f8b1 100644 --- a/lib/private/SpeechToText/SpeechToTextManager.php +++ b/lib/private/SpeechToText/SpeechToTextManager.php @@ -101,16 +101,18 @@ class SpeechToTextManager implements ISpeechToTextManager { } public function transcribeFile(File $file): string { - $provider = current($this->getProviders()); - if (!$provider) { + if (!$this->hasProviders()) { throw new PreConditionNotMetException('No SpeechToText providers have been registered'); } - try { - return $provider->transcribeFile($file); - } catch (\Throwable $e) { - $this->logger->info('SpeechToText transcription failed', ['exception' => $e]); - throw new \RuntimeException('SpeechToText transcription failed: ' . $e->getMessage()); + foreach ($this->getProviders() as $provider) { + try { + return $provider->transcribeFile($file); + } catch (\Throwable $e) { + $this->logger->info('SpeechToText transcription using provider ' . $provider->getName() . ' failed', ['exception' => $e]); + } } + + throw new RuntimeException('Could not transcribe file'); } } -- cgit v1.2.3