From: Vincent Vanwaelscappel Date: Mon, 31 Jan 2022 18:34:38 +0000 (+0100) Subject: wait #5065 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=2a05ca6b82d3ecc1c033ccff09b454e9d6114050;p=cubist_azuretts.git wait #5065 @0.5 --- diff --git a/src/Api.php b/src/Api.php index 04a1037..ba038f6 100644 --- a/src/Api.php +++ b/src/Api.php @@ -41,22 +41,21 @@ class Api $this->client = new Client(); } - public function textToSpeech($text, $locale, $gender, $voiceName) + public function textToSpeech($text, $locale, $gender, $voiceName, $saveToFile) { - $this->checkToken(); + $ssml = ""; + $ssml .= htmlspecialchars($text, ENT_XML1 | ENT_SUBSTITUTE | ENT_QUOTES); + $ssml .= ""; - $ssml = "" . htmlspecialchars($text, ENT_XML1) . ""; - $res = $this->_call('/v1', 'post', [ + $this->_call('/v1', 'post', [ 'X-Microsoft-OutputFormat' => 'audio-48khz-192kbitrate-mono-mp3', 'Content-type' => 'application/ssml+xml' - ], $ssml); - return $res->getBody()->getContents(); + ], $ssml, ['sink' => $saveToFile]); } public function listVoices() { $res = $this->_call('/voices/list'); - return json_decode($res->getBody()->getContents()); } @@ -70,11 +69,13 @@ class Api */ protected function _call($url, $method = 'get', $headers = [], $body = null, $options = []) { + $this->checkToken(); $baseURL = 'https://' . $this->region . '.tts.speech.microsoft.com/cognitiveservices/'; $headers = array_merge([ 'Authorization' => 'Bearer ' . $this->token, 'User-Agent' => 'Cubist TTS Client'], $headers); + return $this->client->send(new Request($method, $baseURL . ltrim($url, '/'), $headers, $body), $options); }