use Cubist\Azure\TTS\Api;
use Cubist\Backpack\Magic\Fields\SelectFromArray;
+use Illuminate\Support\Facades\Cache;
class FluidbookTTSVoice extends SelectFromArray
{
public function getOptions()
{
if (null === static::$_ttsVoices) {
- static::$_ttsVoices = ['' => ''];
+ static::$_ttsVoices = static::getTTSVoices();
+ }
+ return static::$_ttsVoices;
+ }
+ public static function getTTSVoices($force = false)
+ {
+ $cacheKey = 'fluidbook_tts_voices';
+ if ($force) {
+ Cache::forget($cacheKey);
+ }
+ return Cache::remember($cacheKey, 3600, function () {
+ start_measure('Get TTS Voices in Field');
+ $res = ['' => ''];
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'] . ')';
+ $res['azuretts:' . $voice['Locale'] . '/' . $voice['Gender'] . '/' . $voice['ShortName']] = 'Azure ' . $voice['DisplayName'] . ' (' . $voice['Locale'] . ')';
}
}
} catch (\Exception $e) {
}
- 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)';
+ 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)';
}
- static::$_ttsVoices = array_merge(static::$_ttsVoices, ['festival:voice_cmu_us_slt_arctic_hts' => 'Festival (en-US)',
+ $res = 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;
+ stop_measure('Get TTS Voices in Field');
+ return $res;
+ });
}
}
*/
protected $_settingsData = null;
- protected static array $defaultSettingsAttributes = ['fake' => true, 'translatable' => false, 'store_in' => 'settings','default'=>''];
+ protected static array $defaultSettingsAttributes = ['fake' => true, 'translatable' => false, 'store_in' => 'settings', 'default' => ''];
/**
*/
public function addSettingField($name, $type = 'Text', $label = '', $attributes = [])
{
+ start_measure('add setting field ' . $name);
$attributes = self::normalizeAttributes($name, $type, $label, $attributes);
- return $this->addField($name, $type, $label, array_merge(self::$defaultSettingsAttributes, $attributes));
+ $res = $this->addField($name, $type, $label, array_merge(self::$defaultSettingsAttributes, $attributes));
+ stop_measure('add setting field ' . $name);
+ return $res;
}
}