PHP code example of runapi-ai / gemini-tts
1. Go to this page and download the library: Download runapi-ai/gemini-tts library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
runapi-ai / gemini-tts example snippets
unApi\GeminiTts\GeminiTtsClient;
$client = new GeminiTtsClient(); // reads RUNAPI_API_KEY
$task = $client->textToSpeech->create([
'model' => 'gemini-2.5-pro-tts',
'dialogue_turns' => [['speaker_id' => 'Speaker 1', 'text' => 'Welcome.']],
'sample_context' => 'sample',
'scene' => 'sample',
'speakers' => [['speaker_id' => 'Speaker 1', 'voice_name' => 'Fenrir', 'accent' => 'British (RP)', 'style' => 'Deadpan', 'pace' => 'Natural']],
'temperature' => 0.5,
]);
$status = $client->textToSpeech->get($task->id);
$result = $client->textToSpeech->run([
'model' => 'gemini-2.5-pro-tts',
'dialogue_turns' => [['speaker_id' => 'Speaker 1', 'text' => 'Welcome.']],
'sample_context' => 'sample',
'scene' => 'sample',
'speakers' => [['speaker_id' => 'Speaker 1', 'voice_name' => 'Fenrir', 'accent' => 'British (RP)', 'style' => 'Deadpan', 'pace' => 'Natural']],
'temperature' => 0.5,
]);
echo $result->audios[0]->url . PHP_EOL;