Copy PHP Code
<?php
/**
* VoiceCraft Pro - Voicemaker.in Official API Handler
* Endpoint: https://developer.voicemaker.in/voice/generate
* Languages: English (en-US, en-IN), Tamil (ta-IN), Telugu (te-IN)
*/
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
exit(0);
}
// Configurable Parameters
$api_key = getenv('VOICEMAKER_API_KEY') ?: 'YOUR_VOICEMAKER_API_KEY_HERE';
$text = isset($_POST['text']) ? trim($_POST['text']) : 'Welcome to Voicemaker AI Text to Speech';
$voice_id = isset($_POST['voice_id']) ? trim($_POST['voice_id']) : 'ai3-Matthew';
$engine = isset($_POST['engine']) ? trim($_POST['engine']) : 'neural'; // 'neural', 'proplus', 'turbo'
$sample_rate = isset($_POST['sample_rate']) ? intval($_POST['sample_rate']) : 44100;
$speed = isset($_POST['speed']) ? floatval($_POST['speed']) : 0; // range: -100 to 100
$pitch = isset($_POST['pitch']) ? floatval($_POST['pitch']) : 0; // range: -20 to 20
$voxfx = isset($_POST['voxfx']) ? trim($_POST['voxfx']) : 'none';
if (empty($text)) {
http_response_code(400);
echo json_encode(['error' => 'Text parameter is required']);
exit;
}
// Prepare Voicemaker.in Payload
$payload = [
'Engine' => $engine,
'VoiceId' => $voice_id,
'Text' => $text,
'OutputFormat' => 'mp3',
'SampleRate' => (string)$sample_rate,
'MasterSpeed' => (string)$speed,
'MasterPitch' => (string)$pitch,
'MasterVolume' => '0'
];
if ($voxfx !== 'none') {
$payload['Effect'] = $voxfx;
}
$ch = curl_init('https://developer.voicemaker.in/voice/generate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $api_key
]);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code === 200) {
$result = json_decode($response, true);
if (isset($result['path'])) {
// Return JSON response containing Voicemaker generated audio file URL
header('Content-Type: application/json');
echo json_encode([
'success' => true,
'audio_url' => $result['path'],
'voice_id' => $voice_id
]);
exit;
}
}
http_response_code($http_code ?: 500);
echo json_encode([
'success' => false,
'error' => 'Voicemaker API execution failed',
'details' => json_decode($response, true) ?: $response
]);
?>