function elapro_generate_audio($text) { $api_key = get_option('el_api_key'); $voice_id = get_option('el_voice_id'); $model_id = get_option('el_model_id'); $response = wp_remote_post( "https://api.elevenlabs.io/v1/text-to-speech/$voice_id", [ 'timeout' => 60, 'headers' => [ 'xi-api-key' => $api_key, 'Content-Type' => 'application/json', 'Accept' => 'audio/mpeg' ], 'body' => json_encode([ "text" => $text, "model_id" => $model_id, "voice_settings" => [ "stability" => 0.5, "similarity_boost" => 0.8 ] ]) ] ); if (is_wp_error($response)) return false; $audio_binary = wp_remote_retrieve_body($response); if (empty($audio_binary)) return false; // IMPORTANT: force clean binary save $upload = wp_upload_bits( 'el-audio-' . time() . '.mp3', null, $audio_binary ); if (!empty($upload['url'])) { return $upload['url']; } return false; }