Compare commits

..

2 Commits

Author SHA1 Message Date
Flatlogic Bot
1dedc6920a nice design 2025-09-23 21:45:57 +00:00
Flatlogic Bot
fece30dee1 initial bad layout 2025-09-23 21:41:41 +00:00
6 changed files with 426 additions and 123 deletions

79
assets/css/custom.css Normal file
View File

@ -0,0 +1,79 @@
/* General Body Styles */
body {
background-color: #f8f9fa; /* Light gray background */
font-family: 'Inter', sans-serif;
color: #343a40;
}
/* Header */
header h1 {
font-weight: 600;
}
/* Card Styles */
.card {
border: none;
border-radius: 0.75rem; /* Softer rounded corners */
}
.card-title {
font-weight: 500;
color: #495057;
}
/* Waveform Canvas */
#waveform {
width: 100%;
height: 150px; /* Adjusted height */
}
.bg-light {
background-color: #e9ecef !important;
}
/* Buttons */
.btn {
font-weight: 500;
transition: all 0.2s ease-in-out;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.btn-primary {
background-color: #0d6efd;
border-color: #0d6efd;
}
/* Recordings List */
#recordingsList .list-group-item {
background-color: #fff;
border: 1px solid #dee2e6;
border-radius: 0.5rem;
margin-bottom: 0.75rem;
transition: background-color 0.2s ease;
}
#recordingsList .list-group-item:hover {
background-color: #f1f3f5;
}
#recordingsList .btn-play {
background-color: #198754; /* Green play button */
color: white;
}
#recordingsList .btn-play:hover {
background-color: #157347;
}
#recordingsList .recording-name {
font-weight: 500;
}
/* Footer */
footer {
font-size: 0.9rem;
}

194
assets/js/main.js Normal file
View File

@ -0,0 +1,194 @@
document.addEventListener('DOMContentLoaded', () => {
console.log('DOM fully loaded and parsed');
const startRecordBtn = document.getElementById('startRecordBtn');
const stopRecordBtn = document.getElementById('stopRecordBtn');
const saveRecordBtn = document.getElementById('saveRecordBtn');
const waveformCanvas = document.getElementById('waveform');
const recordingsList = document.getElementById('recordingsList');
const canvasCtx = waveformCanvas.getContext('2d');
let mediaRecorder;
let audioChunks = [];
let audioContext;
let analyser;
let source;
let animationFrameId;
let streamReference; // Keep a reference to the stream
async function loadRecordings() {
console.log('Loading recordings...');
try {
const response = await fetch('list_recordings.php');
const recordings = await response.json();
console.log('Recordings found:', recordings);
recordingsList.innerHTML = '';
if (recordings.length > 0) {
const list = document.createElement('div');
list.className = 'list-group';
recordings.forEach(recording => {
const fileName = recording.split('/').pop();
const card = document.createElement('div');
card.className = 'list-group-item list-group-item-action d-flex justify-content-between align-items-center';
const nameSpan = document.createElement('span');
nameSpan.className = 'recording-name';
nameSpan.textContent = fileName;
const playBtn = document.createElement('button');
playBtn.className = 'btn btn-play btn-sm rounded-pill';
playBtn.innerHTML = '<i class="bi bi-play-fill"></i>';
playBtn.onclick = () => {
const audio = new Audio(recording);
audio.play();
};
card.appendChild(nameSpan);
card.appendChild(playBtn);
list.appendChild(card);
});
recordingsList.appendChild(list);
} else {
recordingsList.innerHTML = '<div class="text-center text-muted p-4"><p>No recordings yet.</p><small>Your saved recordings will appear here.</small></div>';
}
} catch (error) {
console.error('Failed to load recordings:', error);
recordingsList.innerHTML = '<p class="text-center text-danger">Could not load recordings.</p>';
}
}
startRecordBtn.addEventListener('click', async () => {
console.log('Start recording button clicked');
try {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
streamReference = stream; // Save stream reference
console.log('Microphone access granted');
startRecordBtn.disabled = true;
stopRecordBtn.disabled = false;
saveRecordBtn.style.display = 'none';
console.log('UI updated for recording start');
audioContext = new (window.AudioContext || window.webkitAudioContext)();
analyser = audioContext.createAnalyser();
source = audioContext.createMediaStreamSource(stream);
source.connect(analyser);
analyser.fftSize = 2048;
const bufferLength = analyser.frequencyBinCount;
const dataArray = new Uint8Array(bufferLength);
const draw = () => {
animationFrameId = requestAnimationFrame(draw);
analyser.getByteTimeDomainData(dataArray);
canvasCtx.fillStyle = '#e9ecef'; // Match the light background
canvasCtx.fillRect(0, 0, waveformCanvas.width, waveformCanvas.height);
canvasCtx.lineWidth = 2;
canvasCtx.strokeStyle = '#0d6efd'; // Primary button color
canvasCtx.beginPath();
const sliceWidth = waveformCanvas.width * 1.0 / bufferLength;
let x = 0;
for (let i = 0; i < bufferLength; i++) {
const v = dataArray[i] / 128.0;
const y = v * waveformCanvas.height / 2;
if (i === 0) {
canvasCtx.moveTo(x, y);
} else {
canvasCtx.lineTo(x, y);
}
x += sliceWidth;
}
canvasCtx.lineTo(waveformCanvas.width, waveformCanvas.height / 2);
canvasCtx.stroke();
};
draw();
console.log('Waveform drawing started');
audioChunks = [];
mediaRecorder = new MediaRecorder(stream);
mediaRecorder.ondataavailable = event => {
console.log('Audio data available, chunk size:', event.data.size);
audioChunks.push(event.data);
};
mediaRecorder.onstop = () => {
console.log('MediaRecorder stopped and onstop event fired.');
if (streamReference) {
streamReference.getTracks().forEach(track => track.stop());
console.log('Microphone stream tracks stopped.');
}
startRecordBtn.disabled = false;
stopRecordBtn.disabled = true;
saveRecordBtn.style.display = 'inline-block';
console.log('Save button is now visible');
cancelAnimationFrame(animationFrameId);
if (audioContext && audioContext.state !== 'closed') {
audioContext.close().then(() => console.log('AudioContext closed'));
}
};
mediaRecorder.start();
console.log('MediaRecorder started');
} catch (err) {
console.error('Error starting recording:', err);
alert('Could not start recording. Please ensure you have a microphone and have granted permission.');
startRecordBtn.disabled = false;
stopRecordBtn.disabled = true;
}
});
stopRecordBtn.addEventListener('click', () => {
console.log('Stop recording button clicked');
if (mediaRecorder && mediaRecorder.state === 'recording') {
mediaRecorder.stop();
} else {
console.warn('Stop button clicked but mediaRecorder is not recording.');
}
});
saveRecordBtn.addEventListener('click', () => {
console.log('Save recording button clicked');
if (audioChunks.length === 0) {
console.error('No audio chunks to save.');
alert('There is no audio to save.');
return;
}
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
const formData = new FormData();
formData.append('audio_data', audioBlob, 'recording.wav');
console.log('Sending audio data to server. Blob size:', audioBlob.size);
fetch('save_audio.php', {
method: 'POST',
body: formData
})
.then(response => {
console.log('Received response from save_audio.php');
if (!response.ok) {
throw new Error(`Server responded with ${response.status}`);
}
return response.json();
})
.then(data => {
console.log('Server response:', data);
if (data.success) {
alert('Recording saved!');
saveRecordBtn.style.display = 'none';
loadRecordings();
} else {
const errorMessage = data.error || 'An unknown error occurred.';
alert('Error saving recording: ' + errorMessage);
console.error('Server-side save error:', errorMessage);
}
})
.catch(error => {
console.error('Error saving recording:', error);
alert('An error occurred while saving the recording. Check the console for details.');
});
});
loadRecordings();
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 KiB

182
index.php
View File

@ -1,131 +1,67 @@
<?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>New Style</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}
.loader {
margin: 1.25rem auto 1.25rem;
width: 48px;
height: 48px;
border: 3px solid rgba(255, 255, 255, 0.25);
border-top-color: #fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.hint {
opacity: 0.9;
}
.sr-only {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; border: 0;
}
h1 {
font-size: 3rem;
font-weight: 700;
margin: 0 0 1rem;
letter-spacing: -1px;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
}
code {
background: rgba(0,0,0,0.2);
padding: 2px 6px;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
footer {
position: absolute;
bottom: 1rem;
font-size: 0.8rem;
opacity: 0.7;
}
</style>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Audio Recorder & Visualizer</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<link href="assets/css/custom.css?v=<?php echo time(); ?>" rel="stylesheet">
</head>
<body>
<main>
<div class="card">
<h1>Analyzing your requirements and generating your website…</h1>
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
<span class="sr-only">Loading…</span>
</div>
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWiZZy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
<p class="hint">This page will update automatically as the plan is implemented.</p>
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
<header class="p-3 mb-4 text-center">
<h1 class="display-5">Audio Recorder</h1>
<p class="lead text-muted">Record, visualize, and save your audio with ease.</p>
</header>
<div class="container-fluid px-4">
<div class="row g-4">
<!-- Left Column: Recorder -->
<div class="col-lg-7">
<div class="card shadow-sm h-100">
<div class="card-body d-flex flex-column">
<h5 class="card-title mb-3">Recorder</h5>
<div class="flex-grow-1 d-flex align-items-center justify-content-center bg-light rounded p-3">
<canvas id="waveform"></canvas>
</div>
<div class="d-flex justify-content-center align-items-center mt-4">
<button id="startRecordBtn" class="btn btn-primary btn-lg rounded-pill px-4 me-3">
<i class="bi bi-mic-fill me-2"></i>Start Recording
</button>
<button id="stopRecordBtn" class="btn btn-danger btn-lg rounded-pill px-4" disabled>
<i class="bi bi-stop-fill me-2"></i>Stop
</button>
<button id="saveRecordBtn" class="btn btn-success btn-lg rounded-pill px-4" style="display: none;">
<i class="bi bi-save-fill me-2"></i>Save Recording
</button>
</div>
</div>
</div>
</div>
<!-- Right Column: Library -->
<div class="col-lg-5">
<div class="card shadow-sm h-100">
<div class="card-body">
<h5 class="card-title mb-3">Library</h5>
<div id="recordingsList" class="overflow-auto" style="max-height: 400px;">
<!-- Recordings will be loaded here -->
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC)
</footer>
<footer class="text-center text-muted mt-5 pb-3">
<p>&copy; 2025 Audio Recorder. All Rights Reserved.</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>

17
list_recordings.php Normal file
View File

@ -0,0 +1,17 @@
<?php
header('Content-Type: application/json');
$uploadDir = 'uploads/';
$recordings = [];
if (is_dir($uploadDir)) {
$files = scandir($uploadDir);
foreach ($files as $file) {
if ($file !== '.' && $file !== '..') {
$recordings[] = $uploadDir . $file;
}
}
}
echo json_encode($recordings);
?>

77
save_audio.php Normal file
View File

@ -0,0 +1,77 @@
<?php
header('Content-Type: application/json');
$response = [];
// The directory where recordings will be stored.
$uploadDir = 'uploads/';
// Check if the upload directory exists and is writable.
if (!is_dir($uploadDir)) {
// Try to create it if it doesn't exist.
if (!mkdir($uploadDir, 0775, true)) {
$response = ['success' => false, 'error' => 'Server error: Cannot create upload directory.'];
echo json_encode($response);
exit;
}
}
if (!is_writable($uploadDir)) {
$response = ['success' => false, 'error' => 'Server error: The uploads directory is not writable. Please check file permissions.'];
echo json_encode($response);
exit;
}
// Check if a file was uploaded and there are no errors.
if (isset($_FILES['audio_data']) && $_FILES['audio_data']['error'] == UPLOAD_ERR_OK) {
// Get the temporary file path of the uploaded file.
$tmpName = $_FILES['audio_data']['tmp_name'];
// Generate a unique filename to prevent overwriting existing files.
$fileName = 'recording_' . date('Y-m-d_H-i-s') . '_' . uniqid() . '.wav';
$filePath = $uploadDir . $fileName;
// Move the uploaded file from the temporary directory to the final destination.
if (move_uploaded_file($tmpName, $filePath)) {
$response['success'] = true;
$response['message'] = 'Audio saved successfully.';
$response['file_path'] = $filePath;
} else {
$response['success'] = false;
$response['error'] = 'Error saving audio file after upload. Check directory permissions.';
}
} else {
// Handle potential upload errors.
$error_message = 'No audio data received or an upload error occurred.';
if (isset($_FILES['audio_data']['error'])) {
switch ($_FILES['audio_data']['error']) {
case UPLOAD_ERR_INI_SIZE:
$error_message = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
break;
case UPLOAD_ERR_FORM_SIZE:
$error_message = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';
break;
case UPLOAD_ERR_PARTIAL:
$error_message = 'The uploaded file was only partially uploaded.';
break;
case UPLOAD_ERR_NO_FILE:
$error_message = 'No file was uploaded.';
break;
case UPLOAD_ERR_NO_TMP_DIR:
$error_message = 'Missing a temporary folder.';
break;
case UPLOAD_ERR_CANT_WRITE:
$error_message = 'Failed to write file to disk.';
break;
case UPLOAD_ERR_EXTENSION:
$error_message = 'A PHP extension stopped the file upload.';
break;
}
}
$response['success'] = false;
$response['error'] = $error_message;
}
echo json_encode($response);
?>