1. Go to this page and download the library: Download naiuz/sdk 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/ */
use Naiuz\NeuronAI;
$client = new NeuronAI([
'api_key' => 'nai_...', // else NEURONAI_API_KEY
'base_url' => 'https://my.neuronai.uz/api/v1', // else NEURONAI_BASE_URL, else this address
'timeout' => 300, // seconds each attempt may take: 5 minutes by default
'max_retries' => 2, // retries of a failed attempt: 2 by default
'default_headers' => ['x-app' => 'shop'], // sent with every call
]);
use Naiuz\Exceptions\WaitTimeoutException;
$longText = str_repeat("Bir bor ekan, bir yo'q ekan. ", 100);
try {
$job = $client->tts->jobs->createAndWait(
['text' => $longText, 'voice_id' => 'kamron'],
['idempotency_key' => 'chapter-7', 'poll_interval' => 2, 'timeout' => 600],
);
if ($job->status === 'succeeded') {
$client->tts->jobs->audio($job->id)->save('chapter.wav');
} elseif ($job->error !== null) {
echo "{$job->error->code}: {$job->error->message}\n";
}
} catch (WaitTimeoutException $error) {
// The wait ran out first: the job may still finish, so fetch its audio later.
echo "Still {$error->job->status}: {$error->job->id}\n";
}
$voice = $client->voices->create([
'name' => 'Office voice',
'language' => 'uz',
'ref_audio' => 'sample.wav', // a path
'ref_text' => 'Salom, men sizga yordam beraman.',
'tags' => ['support', 'calm'],
]);
$stream = fopen('call.mp3', 'rb');
if ($stream === false) {
exit("call.mp3 can't be opened.\n");
}
$transcription = $client->stt->transcribe([
'file' => ['stream' => $stream, 'filename' => 'call.mp3'], // a stream, with the filename to send it under
'language' => 'uz',
]);
echo "{$transcription->text} ({$transcription->duration_seconds} s)\n";