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;
}
}