PHP code example of runapi-ai / fish-audio
1. Go to this page and download the library: Download runapi-ai/fish-audio 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 / fish-audio example snippets
unApi\FishAudio\FishAudioClient;
$client = new FishAudioClient(); // reads RUNAPI_API_KEY
$created = $client->createVoice->run([
'name' => 'Narrator',
'source_audio_url' => 'https://cdn.runapi.ai/public/samples/voice.mp3',
]);
$voice = $client->getVoice->run(['voice_id' => $created->voice->voiceId]);
if ($voice->voice->state !== 'trained') {
throw new RuntimeException("Voice is {$voice->voice->state}");
}
$result = $client->textToSpeech->run([
'model' => 's2.1-pro',
'text' => 'Hello from RunAPI [excited]',
'voice_id' => $created->voice->voiceId,
'output_format' => 'wav',
'sample_rate_hz' => 44100,
]);
echo $result->audios[0]->url . PHP_EOL;