Skip to content

Commit 386c7f6

Browse files
authored
Merge pull request #133 from yakupseymen/main
Text to Speech
2 parents 0ca8516 + ab5e06a commit 386c7f6

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ Please visit https://orhanerday.gitbook.io/openai-php-api-1/
123123
- Embeddings
124124
- [x] [Create embeddings](https://beta.openai.com/docs/api-reference/embeddings/create)
125125
- Audio
126+
- [x] [Text to Speech (TTS)](https://platform.openai.com/docs/guides/text-to-speech)
126127
- [x] [Create transcription](https://platform.openai.com/docs/api-reference/audio/create)
127128
- [x] [Create translation](https://platform.openai.com/docs/api-reference/audio/create)
128129
- Files
@@ -660,6 +661,20 @@ $engines = $open_ai->engines();
660661

661662
## Audio
662663

664+
### Text To Speech (TTS)
665+
666+
```php
667+
668+
$result = $open_ai->tts([
669+
"model" => "tts-1", // tts-1-hd
670+
"input" => "I'm going to use the stones again. Hey, we'd be going in short-handed, you know",
671+
"voice" => "alloy", // echo, fable, onyx, nova, and shimmer
672+
]);
673+
674+
// Save audio file
675+
file_put_contents('tts-result.mp3', $result);
676+
```
677+
663678
### Create Transcription
664679

665680
Transcribes audio into the input language.

src/OpenAi.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,18 @@ public function listRunSteps($threadId, $runId, $query = [])
838838
return $this->sendRequest($url, 'GET');
839839
}
840840

841+
/**
842+
* @param $opts
843+
* @return bool|string
844+
*/
845+
public function tts($opts)
846+
{
847+
$url = Url::ttsUrl();
848+
$this->baseUrl($url);
849+
850+
return $this->sendRequest($url, 'POST', $opts);
851+
}
852+
841853
/**
842854
* @param int $timeout
843855
*/

src/Url.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,13 @@ public static function threadsUrl(): string
178178
{
179179
return self::OPEN_AI_URL . "/threads";
180180
}
181+
182+
/**
183+
* @param
184+
* @return string
185+
*/
186+
public static function ttsUrl(): string
187+
{
188+
return self::OPEN_AI_URL . "/audio/speech";
189+
}
181190
}

0 commit comments

Comments
 (0)