![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/private_html/ |
<?php
// API.box Integration Functions
// Based on https://api.box/suno/docs#/
// API Key Management: https://api.box/api-key
require_once 'config/database.php';
class APIBoxFunctions {
private $api_base_url = 'https://api.api.box';
private $api_key;
private $pdo;
public function __construct($api_key) {
$this->api_key = $api_key;
$this->pdo = getDBConnection();
}
// 🎵 Music Generation APIs
/**
* Generate Music - Create high-quality music from text descriptions
*/
public function generateMusic($params) {
$url = $this->api_base_url . '/api/v1/generate';
return $this->makeRequest($url, $params);
}
/**
* Extend Music - Extend existing music tracks with AI-powered continuation
*/
public function extendMusic($params) {
$url = $this->api_base_url . '/api/v1/extend';
return $this->makeRequest($url, $params);
}
/**
* Upload and Cover Audio - Transform existing audio with new styles
*/
public function uploadAndCoverAudio($params) {
$url = $this->api_base_url . '/api/v1/upload-cover';
return $this->makeRequest($url, $params);
}
/**
* Upload and Extend Audio - Upload your own audio and extend it
*/
public function uploadAndExtendAudio($params) {
$url = $this->api_base_url . '/api/v1/upload-extend';
return $this->makeRequest($url, $params);
}
// ✍️ Lyrics Creation APIs
/**
* Generate Lyrics - Create AI-powered lyrics for songs
*/
public function generateLyrics($params) {
$url = $this->api_base_url . '/api/v1/lyrics';
return $this->makeRequest($url, $params);
}
/**
* Get Timestamped Lyrics - Retrieve lyrics with precise timestamps
*/
public function getTimestampedLyrics($params) {
$url = $this->api_base_url . '/api/v1/timestamped-lyrics';
return $this->makeRequest($url, $params);
}
// 🔊 Audio Processing APIs
/**
* Vocal and Instrument Separation - Extract vocals and instrumental tracks
* Supports both 2-stem (vocals/instrumental) and full stem separation
*
* @param array $params Parameters including:
* - audioUrl: URL of the audio file
* - type: 'separate_vocal' (2-stem) or 'split_stem' (full separation)
* - separationType: 'vocals', 'instrumental', or 'both' (for 2-stem mode)
* - quality: 'high', 'medium', or 'low'
* - format: 'mp3', 'wav', or 'm4a'
* - callBackUrl: Webhook URL for completion notification
*/
public function separateVocals($params) {
$url = $this->api_base_url . '/api/v1/separate';
return $this->makeRequest($url, $params);
}
/**
* Convert to WAV Format - Convert generated music to high-quality WAV
*/
public function convertToWAV($params) {
$url = $this->api_base_url . '/api/v1/convert-wav';
return $this->makeRequest($url, $params);
}
/**
* Boost Music Style - Enhance and refine music styles
* Based on https://docs.api.box/suno-api/boost-music-style
* Endpoint: POST /api/v1/style/generate
*/
public function boostMusicStyle($params) {
$url = $this->api_base_url . '/api/v1/style/generate';
return $this->makeRequest($url, $params);
}
/**
* Generate Music Cover - Create covers of existing songs
*/
public function generateMusicCover($params) {
$url = $this->api_base_url . '/api/v1/cover';
return $this->makeRequest($url, $params);
}
/**
* Add Vocals - Generate vocal tracks for instrumental music
* NOTE: This endpoint may not be available yet in API.box
* Based on https://api.box/suno/docs#/
*/
public function addVocals($params) {
// Try alternative endpoint paths
$endpoints = [
'/api/v1/add-vocals',
'/api/v1/vocals',
'/api/v1/generate-vocals',
'/api/v1/music/add-vocals'
];
foreach ($endpoints as $endpoint) {
$url = $this->api_base_url . $endpoint;
$result = $this->makeRequest($url, $params);
// If not 404, return the result
if (!isset($result['http_code']) || $result['http_code'] !== 404) {
return $result;
}
}
// All endpoints failed
return ['error' => 'Add Vocals endpoint not available in API.box yet', 'http_code' => 404];
}
/**
* Add Instrumental - Create instrumental accompaniment for vocal tracks
* NOTE: This endpoint may not be available yet in API.box
* Based on https://api.box/suno/docs#/
*/
public function addInstrumental($params) {
// Try alternative endpoint paths
$endpoints = [
'/api/v1/add-instrumental',
'/api/v1/instrumental',
'/api/v1/generate-instrumental',
'/api/v1/music/add-instrumental'
];
foreach ($endpoints as $endpoint) {
$url = $this->api_base_url . $endpoint;
$result = $this->makeRequest($url, $params);
// If not 404, return the result
if (!isset($result['http_code']) || $result['http_code'] !== 404) {
return $result;
}
}
// All endpoints failed
return ['error' => 'Add Instrumental endpoint not available in API.box yet', 'http_code' => 404];
}
/**
* Replace Music Section - Replace specific sections of tracks
* NOTE: This endpoint may not be available yet in API.box
* Based on https://api.box/suno/docs#/
*/
public function replaceMusicSection($params) {
// Try alternative endpoint paths
$endpoints = [
'/api/v1/replace-section',
'/api/v1/replace',
'/api/v1/section-replace',
'/api/v1/music/replace-section'
];
foreach ($endpoints as $endpoint) {
$url = $this->api_base_url . $endpoint;
$result = $this->makeRequest($url, $params);
// If not 404, return the result
if (!isset($result['http_code']) || $result['http_code'] !== 404) {
return $result;
}
}
// All endpoints failed
return ['error' => 'Replace Section endpoint not available in API.box yet', 'http_code' => 404];
}
/**
* Generate Persona - Create AI personas for consistent vocal styles
* NOTE: This endpoint may not be available yet in API.box
* Based on https://api.box/suno/docs#/
*/
public function generatePersona($params) {
// Try alternative endpoint paths
$endpoints = [
'/api/v1/persona',
'/api/v1/personas',
'/api/v1/generate-persona',
'/api/v1/music/persona'
];
foreach ($endpoints as $endpoint) {
$url = $this->api_base_url . $endpoint;
$result = $this->makeRequest($url, $params);
// If not 404, return the result
if (!isset($result['http_code']) || $result['http_code'] !== 404) {
return $result;
}
}
// All endpoints failed
return ['error' => 'Generate Persona endpoint not available in API.box yet', 'http_code' => 404];
}
// 🎬 Music Video APIs
/**
* Create Music Video - Generate visual music videos from audio tracks
*/
public function createMusicVideo($params) {
$url = $this->api_base_url . '/api/v1/video';
return $this->makeRequest($url, $params);
}
// 🛠️ Utility APIs
/**
* Get Music Generation Details - Monitor and retrieve task details
*/
public function getMusicGenerationDetails($taskId) {
$url = $this->api_base_url . '/api/v1/details/' . $taskId;
return $this->makeRequest($url, [], 'GET');
}
/**
* Get Lyrics Generation Details - Track lyrics generation status
*/
public function getLyricsGenerationDetails($taskId) {
$url = $this->api_base_url . '/api/v1/lyrics-details/' . $taskId;
return $this->makeRequest($url, [], 'GET');
}
/**
* Get WAV Conversion Details - Monitor WAV conversion tasks
*/
public function getWAVConversionDetails($taskId) {
$url = $this->api_base_url . '/api/v1/wav-details/' . $taskId;
return $this->makeRequest($url, [], 'GET');
}
/**
* Get Vocal Separation Details - Check vocal separation progress
*/
public function getVocalSeparationDetails($taskId) {
$url = $this->api_base_url . '/api/v1/separation-details/' . $taskId;
return $this->makeRequest($url, [], 'GET');
}
/**
* Get Music Video Details - Track video generation progress
*/
public function getMusicVideoDetails($taskId) {
$url = $this->api_base_url . '/api/v1/video-details/' . $taskId;
return $this->makeRequest($url, [], 'GET');
}
/**
* Get Music Cover Details - Track cover generation progress
*/
public function getMusicCoverDetails($taskId) {
$url = $this->api_base_url . '/api/v1/cover-details/' . $taskId;
return $this->makeRequest($url, [], 'GET');
}
/**
* Get Add Vocals Details - Track vocal addition progress
* Based on https://api.box/suno/docs#/
*/
public function getAddVocalsDetails($taskId) {
$url = $this->api_base_url . '/api/v1/add-vocals-details/' . $taskId;
return $this->makeRequest($url, [], 'GET');
}
/**
* Get Add Instrumental Details - Track instrumental addition progress
* Based on https://api.box/suno/docs#/
*/
public function getAddInstrumentalDetails($taskId) {
$url = $this->api_base_url . '/api/v1/add-instrumental-details/' . $taskId;
return $this->makeRequest($url, [], 'GET');
}
/**
* Get Replace Section Details - Track section replacement progress
* Based on https://api.box/suno/docs#/
*/
public function getReplaceSectionDetails($taskId) {
$url = $this->api_base_url . '/api/v1/replace-section-details/' . $taskId;
return $this->makeRequest($url, [], 'GET');
}
/**
* Get Persona Details - Track persona generation progress
* Based on https://api.box/suno/docs#/
*/
public function getPersonaDetails($taskId) {
$url = $this->api_base_url . '/api/v1/persona-details/' . $taskId;
return $this->makeRequest($url, [], 'GET');
}
/**
* Get Boost Style Details - Track style boost progress
* Based on https://api.box/suno/docs#/
*/
public function getBoostStyleDetails($taskId) {
$url = $this->api_base_url . '/api/v1/style-details/' . $taskId;
return $this->makeRequest($url, [], 'GET');
}
/**
* Get Remaining Credits - Check account credit balance
* NOTE: Try alternative endpoint paths if default doesn't work
*/
public function getRemainingCredits() {
// Try alternative endpoint paths
$endpoints = [
'/api/v1/credits',
'/api/v1/account/credits',
'/api/v1/user/credits',
'/api/v1/balance'
];
foreach ($endpoints as $endpoint) {
$url = $this->api_base_url . $endpoint;
$result = $this->makeRequest($url, [], 'GET');
// If not 404, return the result
if (!isset($result['http_code']) || $result['http_code'] !== 404) {
return $result;
}
}
// All endpoints failed
return ['error' => 'Credits endpoint not available in API.box yet', 'http_code' => 404];
}
// File Upload APIs
/**
* Base64 File Upload - Upload files using base64 encoding
*/
public function uploadBase64File($params) {
$url = $this->api_base_url . '/api/v1/upload-base64';
return $this->makeRequest($url, $params);
}
/**
* File Stream Upload - Upload files using stream
*/
public function uploadFileStream($params) {
$url = $this->api_base_url . '/api/v1/upload-stream';
return $this->makeRequest($url, $params);
}
/**
* URL File Upload - Upload files from URL
*/
public function uploadFileFromURL($params) {
$url = $this->api_base_url . '/api/v1/upload-url';
return $this->makeRequest($url, $params);
}
// Core request method
private function makeRequest($url, $data = [], $method = 'POST') {
$ch = curl_init();
if ($method === 'POST') {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $this->api_key,
'Content-Type: application/json',
'User-Agent: SoundStudioPro-Music/2.0'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_error = curl_error($ch);
curl_close($ch);
// Log the request
error_log("API Request to: $url");
error_log("HTTP Code: $http_code");
error_log("Response: $response");
if ($curl_error) {
error_log("CURL Error: " . $curl_error);
return ['error' => 'Network error: ' . $curl_error];
}
$result = json_decode($response, true);
if ($http_code === 200 && $result) {
return $result;
} else {
return ['error' => 'API error', 'http_code' => $http_code, 'response' => $result];
}
}
// Database integration methods
/**
* Create track record in database
*/
public function createTrackRecord($userId, $taskId, $title, $prompt, $musicType, $metadata = []) {
try {
$stmt = $this->pdo->prepare("
INSERT INTO music_tracks (user_id, task_id, title, prompt, music_type, status, metadata, is_public, created_at)
VALUES (?, ?, ?, ?, ?, 'processing', ?, 0, NOW())
");
$result = $stmt->execute([
$userId,
$taskId,
$title,
$prompt,
$musicType,
json_encode($metadata)
]);
if ($result) {
return $this->pdo->lastInsertId();
}
return false;
} catch (Exception $e) {
error_log("Database error: " . $e->getMessage());
return false;
}
}
/**
* Update track status
*/
public function updateTrackStatus($taskId, $status, $audioUrl = null, $videoUrl = null, $lyrics = null, $metadata = null) {
try {
$updates = ['status = ?'];
$params = [$status];
if ($audioUrl !== null) {
$updates[] = 'audio_url = ?';
$params[] = $audioUrl;
}
if ($videoUrl !== null) {
$updates[] = 'video_url = ?';
$params[] = $videoUrl;
}
if ($lyrics !== null) {
$updates[] = 'lyrics = ?';
$params[] = $lyrics;
}
if ($metadata !== null) {
$updates[] = 'metadata = ?';
$params[] = json_encode($metadata);
}
$params[] = $taskId;
$sql = "UPDATE music_tracks SET " . implode(', ', $updates) . " WHERE task_id = ?";
$stmt = $this->pdo->prepare($sql);
return $stmt->execute($params);
} catch (Exception $e) {
error_log("Update track error: " . $e->getMessage());
return false;
}
}
}
// Usage example:
// $api = new APIBoxFunctions('your_api_key_here');
// $result = $api->generateMusic(['prompt' => 'Create a rock song', 'model' => 'V4_5']);
?>