Skip to content

Official PHP client for the ResponsiveVoice Text-to-Speech API. Source: sdk-php.

Terminal window
composer require responsivevoice/sdk
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use ResponsiveVoice\Sdk\Api\SynthesisApi;
use ResponsiveVoice\Sdk\Api\VoicesApi;
use ResponsiveVoice\Sdk\Configuration;
$config = (new Configuration())
->setApiKey('X-API-Key', getenv('RESPONSIVEVOICE_API_KEY'))
->setApiKey('X-API-Secret', getenv('RESPONSIVEVOICE_API_SECRET'));
// Synthesize speech — returns raw MP3 bytes.
$audio = (new SynthesisApi(new Client(), $config))
->v2TextSynthesizeGet('Hello world', 'UK English Female');
file_put_contents('hello.mp3', $audio);
// List voices, optionally filtered by language.
$voices = (new VoicesApi(new Client(), $config))->v2VoicesGet()->getVoices();

Server-side callers send an API key + secret pair as X-API-Key + X-API-Secret headers. Get both from your website's settings in the ResponsiveVoice dashboard (sign up): the API key from the "Your site code" snippet, and the API secret under "Server-to-server API secrets" (shown only once, revocable). PHP runs server-side, which is exactly where the secret belongs — browser apps use @responsivevoice/core, which authenticates by origin and needs no secret.