Skip to content

Commit

Permalink
Merge pull request #133 from yakupseymen/main
Browse files Browse the repository at this point in the history
Text to Speech
  • Loading branch information
orhanerday authored Jan 25, 2024
2 parents 0ca8516 + ab5e06a commit 386c7f6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions src/OpenAi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

0 comments on commit 386c7f6

Please sign in to comment.