diff --git a/README.md b/README.md index 8ec6d3c..762bc93 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ Please visit https://orhanerday.gitbook.io/openai-php-api-1/ - Embeddings - [x] [Create embeddings](https://beta.openai.com/docs/api-reference/embeddings/create) - Audio + - [x] [Text to Speech (TTS)](https://platform.openai.com/docs/guides/text-to-speech) - [x] [Create transcription](https://platform.openai.com/docs/api-reference/audio/create) - [x] [Create translation](https://platform.openai.com/docs/api-reference/audio/create) - Files @@ -660,6 +661,20 @@ $engines = $open_ai->engines(); ## Audio +### Text To Speech (TTS) + +```php + +$result = $open_ai->tts([ + "model" => "tts-1", // tts-1-hd + "input" => "I'm going to use the stones again. Hey, we'd be going in short-handed, you know", + "voice" => "alloy", // echo, fable, onyx, nova, and shimmer +]); + +// Save audio file +file_put_contents('tts-result.mp3', $result); +``` + ### Create Transcription Transcribes audio into the input language. diff --git a/src/OpenAi.php b/src/OpenAi.php index e3ff4c7..d9585a2 100644 --- a/src/OpenAi.php +++ b/src/OpenAi.php @@ -838,6 +838,18 @@ public function listRunSteps($threadId, $runId, $query = []) return $this->sendRequest($url, 'GET'); } + /** + * @param $opts + * @return bool|string + */ + public function tts($opts) + { + $url = Url::ttsUrl(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + /** * @param int $timeout */ diff --git a/src/Url.php b/src/Url.php index 4808c77..f3c90ef 100644 --- a/src/Url.php +++ b/src/Url.php @@ -178,4 +178,13 @@ public static function threadsUrl(): string { return self::OPEN_AI_URL . "/threads"; } + + /** + * @param + * @return string + */ + public static function ttsUrl(): string + { + return self::OPEN_AI_URL . "/audio/speech"; + } }