PHP code example of atlasaidev / atlasvoice-sdk

1. Go to this page and download the library: Download atlasaidev/atlasvoice-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/ */

    

atlasaidev / atlasvoice-sdk example snippets


use AtlasVoice\Sdk\Adapters\Plain_Php;

$voice = Plain_Php::client( getenv( 'ATLASVOICE_KEY' ), 'my-app/1.0' );

$result = $voice->synthesize( 'Hello! This is AtlasVoice.', 'en' );

if ( $result->ok() ) {
    file_put_contents( 'hello.mp3', $result->data );
} else {
    echo $result->code();          // e.g. quota_exceeded
    echo $result->request_id;      // quote this to support
}

use AtlasVoice\Sdk\Client;

$ref = Client::job_ref( 'article:42:en' );
$job = $voice->create_job( $text, 'en', array(
    'ref'             => $ref,
    'idempotency_key' => Client::idempotency_key( $ref, $text ), // a retry is never billed twice
) );

// Later (a queue worker or a cron job, never inside a visitor's request):
$status = $voice->get_job( $job->data['job']['id'] );
if ( 'done' === $status->data['job']['status'] ) {
    $hosts = $voice->health()->data['file_hosts'];
    $mp3   = $voice->download( $status->data['job']['file']['url'], $hosts );
}

$all     = $voice->voices();                 // every voice (no key is sent)
$english = $voice->voices( 'en' );           // one language
$natural = $voice->voices( 'en', 'cloud' );  // the Premium natural voices: id, name, locale, gender

$voice = Plain_Php::client( $key, 'my-app/1.0', Plain_Php::DEFAULT_URL, new MyCacheStateStore(), new MyLogger() );