From c4da32b45302fa22e871cf1d01f7beb9ed7576ad Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 5 Feb 2026 16:04:16 +0100 Subject: [PATCH] wip #7977 @3 --- src/Api.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Api.php b/src/Api.php index 3c70f7b..f3fb965 100644 --- a/src/Api.php +++ b/src/Api.php @@ -6,6 +6,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Log; class Api { @@ -44,15 +45,24 @@ class Api public function textToSpeech($text, $locale, $gender, $voiceName, $saveToFile) { + if (stristr('|', $locale)) { + $e = explode('|', $locale); + $locale = $e[1]; + } + $ssml = ""; $text = self::stripNonSSMLTags($text); $ssml .= htmlspecialchars($text, ENT_XML1 | ENT_SUBSTITUTE | ENT_QUOTES); $ssml .= ""; + Log::info('TTS ' . mb_strlen($text) . ' chars // ' . $locale . ' // ' . $gender . ' // ' . $voiceName . ' :: ' . $ssml); + $this->_call('/v1', 'post', [ 'X-Microsoft-OutputFormat' => 'audio-48khz-192kbitrate-mono-mp3', 'Content-type' => 'application/ssml+xml' ], $ssml, ['sink' => $saveToFile]); + + } public static function stripNonSSMLTags($text, $additional_allowed_tags = '') @@ -64,10 +74,12 @@ class Api * @param $raw * @return array|false */ - public function listVoices($raw = false) + public function listVoices($raw = false, $force = false) { $cacheKey = 'azure_tts_voices_' . $raw; - Cache::forget($cacheKey); + if ($force) { + Cache::forget($cacheKey); + } return Cache::remember($cacheKey, 86400, function () use ($raw) { return $this->_listVoices($raw); }); @@ -89,7 +101,14 @@ class Api } $res = []; foreach ($j as $voice) { - $res[$voice['Locale'] . '/' . $voice['Gender'] . '/' . $voice['ShortName']] = $voice['DisplayName'] . ' / ' . $voice['Gender'] . ' / ' . $voice['LocaleName']; + if (isset($voice['SecondaryLocaleList'])) { + foreach ($voice['SecondaryLocaleList'] as $secVoice) { + $res[$voice['Locale'] . '|' . $secVoice . '/' . $voice['Gender'] . '/' . $voice['ShortName']] = $voice['DisplayName'] . ' / ' . $voice['Gender'] . ' / ' . $secVoice; + } + } else { + $res[$voice['Locale'] . '/' . $voice['Gender'] . '/' . $voice['ShortName']] = $voice['DisplayName'] . ' / ' . $voice['Gender'] . ' / ' . $voice['LocaleName']; + } + } return $res; } -- 2.39.5