]> _ Git - fluidbook-toolbox.git/commitdiff
wait #4211 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 15 Jun 2023 06:16:51 +0000 (08:16 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 15 Jun 2023 06:16:51 +0000 (08:16 +0200)
app/Fields/FluidbookTTSVoice.php

index 1d4aca54034bd87be92819fb3f12e42392cfc550..8540b9c7efb50de028d184d5432016470778bb41 100644 (file)
@@ -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;
     }
 }