From: Vincent Vanwaelscappel Date: Thu, 15 Jun 2023 06:16:51 +0000 (+0200) Subject: wait #4211 @0.25 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=585fb95350f0afdc89206ff7dbef8294c7bbe1be;p=fluidbook-toolbox.git wait #4211 @0.25 --- diff --git a/app/Fields/FluidbookTTSVoice.php b/app/Fields/FluidbookTTSVoice.php index 1d4aca540..8540b9c7e 100644 --- a/app/Fields/FluidbookTTSVoice.php +++ b/app/Fields/FluidbookTTSVoice.php @@ -7,28 +7,35 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray; class FluidbookTTSVoice extends SelectFromArray { + + /** @var null|array */ + protected static $_ttsVoices = null; + public function getOptions() { - $res[''] = ''; - - try { - $api = new Api(env('AZURE_API_KEY')); - $voices = $api->listVoices(true); - if ($voices) { - foreach ($voices as $key => $voice) { - $res['azuretts:' . $voice['Locale'] . '/' . $voice['Gender'] . '/' . $voice['ShortName']] = 'Azure ' . $voice['DisplayName'] . ' (' . $voice['Locale'] . ')'; + if (null === static::$_ttsVoices) { + static::$_ttsVoices = ['' => '']; + + try { + $api = new Api(env('AZURE_API_KEY')); + $voices = $api->listVoices(true); + if ($voices) { + foreach ($voices as $key => $voice) { + static::$_ttsVoices['azuretts:' . $voice['Locale'] . '/' . $voice['Gender'] . '/' . $voice['ShortName']] = 'Azure ' . $voice['DisplayName'] . ' (' . $voice['Locale'] . ')'; + } } - } - } catch (\Exception $e) { + } catch (\Exception $e) { - } + } - if (count($res) === 1) { - $res['azuretts:fr-FR/Female/fr-FR-DeniseNeural'] = 'Azure Denise (fr-FR)'; - $res['azuretts:fr-FR/Male/fr-FR-HenriNeural'] = 'Azure Henri (fr-FR)'; + if (count(static::$_ttsVoices) === 1) { + static::$_ttsVoices['azuretts:fr-FR/Female/fr-FR-DeniseNeural'] = 'Azure Denise (fr-FR)'; + static::$_ttsVoices['azuretts:fr-FR/Male/fr-FR-HenriNeural'] = 'Azure Henri (fr-FR)'; + } + static::$_ttsVoices = array_merge(static::$_ttsVoices, ['festival:voice_cmu_us_slt_arctic_hts' => 'Festival (en-US)', + 'readspeaker:Sophie/en_us' => 'ReadSpeaker Sophie (en-US)', + 'readspeaker:Marc/en_us' => 'ReadSpeaker Marc (en-US)']); } - return array_merge($res, ['festival:voice_cmu_us_slt_arctic_hts' => 'Festival (en-US)', - 'readspeaker:Sophie/en_us' => 'ReadSpeaker Sophie (en-US)', - 'readspeaker:Marc/en_us' => 'ReadSpeaker Marc (en-US)']); + return static::$_ttsVoices; } }