nice design
This commit is contained in:
parent
fece30dee1
commit
1dedc6920a
@ -1,22 +1,79 @@
|
|||||||
|
/* General Body Styles */
|
||||||
body {
|
body {
|
||||||
background-color: #F0F8FF;
|
background-color: #f8f9fa; /* Light gray background */
|
||||||
font-family: 'Poppins', sans-serif;
|
font-family: 'Inter', sans-serif;
|
||||||
|
color: #343a40;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hero {
|
/* Header */
|
||||||
background-image: url('https://picsum.photos/seed/wave/1200/400');
|
header h1 {
|
||||||
background-size: cover;
|
font-weight: 600;
|
||||||
background-position: center;
|
|
||||||
color: white;
|
|
||||||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Card Styles */
|
||||||
|
.card {
|
||||||
|
border: none;
|
||||||
|
border-radius: 0.75rem; /* Softer rounded corners */
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-title {
|
||||||
|
font-weight: 500;
|
||||||
|
color: #495057;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Waveform Canvas */
|
||||||
#waveform {
|
#waveform {
|
||||||
display: block;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 200px;
|
height: 150px; /* Adjusted height */
|
||||||
background-color: #FFFFFF;
|
|
||||||
border-radius: 0.5rem;
|
|
||||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
@ -24,28 +24,32 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
console.log('Recordings found:', recordings);
|
console.log('Recordings found:', recordings);
|
||||||
recordingsList.innerHTML = '';
|
recordingsList.innerHTML = '';
|
||||||
if (recordings.length > 0) {
|
if (recordings.length > 0) {
|
||||||
const list = document.createElement('ul');
|
const list = document.createElement('div');
|
||||||
list.className = 'list-group';
|
list.className = 'list-group';
|
||||||
recordings.forEach(recording => {
|
recordings.forEach(recording => {
|
||||||
const listItem = document.createElement('li');
|
|
||||||
listItem.className = 'list-group-item d-flex justify-content-between align-items-center';
|
|
||||||
|
|
||||||
// Extract just the filename
|
|
||||||
const fileName = recording.split('/').pop();
|
const fileName = recording.split('/').pop();
|
||||||
listItem.innerText = fileName;
|
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 audio = new Audio(recording);
|
|
||||||
const playBtn = document.createElement('button');
|
const playBtn = document.createElement('button');
|
||||||
playBtn.className = 'btn btn-primary btn-sm';
|
playBtn.className = 'btn btn-play btn-sm rounded-pill';
|
||||||
playBtn.innerText = 'Play';
|
playBtn.innerHTML = '<i class="bi bi-play-fill"></i>';
|
||||||
playBtn.onclick = () => audio.play();
|
playBtn.onclick = () => {
|
||||||
|
const audio = new Audio(recording);
|
||||||
|
audio.play();
|
||||||
|
};
|
||||||
|
|
||||||
listItem.appendChild(playBtn);
|
card.appendChild(nameSpan);
|
||||||
list.appendChild(listItem);
|
card.appendChild(playBtn);
|
||||||
|
list.appendChild(card);
|
||||||
});
|
});
|
||||||
recordingsList.appendChild(list);
|
recordingsList.appendChild(list);
|
||||||
} else {
|
} else {
|
||||||
recordingsList.innerHTML = '<p class="text-center">No recordings yet.</p>';
|
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) {
|
} catch (error) {
|
||||||
console.error('Failed to load recordings:', error);
|
console.error('Failed to load recordings:', error);
|
||||||
@ -76,10 +80,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const draw = () => {
|
const draw = () => {
|
||||||
animationFrameId = requestAnimationFrame(draw);
|
animationFrameId = requestAnimationFrame(draw);
|
||||||
analyser.getByteTimeDomainData(dataArray);
|
analyser.getByteTimeDomainData(dataArray);
|
||||||
canvasCtx.fillStyle = '#F0F8FF';
|
canvasCtx.fillStyle = '#e9ecef'; // Match the light background
|
||||||
canvasCtx.fillRect(0, 0, waveformCanvas.width, waveformCanvas.height);
|
canvasCtx.fillRect(0, 0, waveformCanvas.width, waveformCanvas.height);
|
||||||
canvasCtx.lineWidth = 2;
|
canvasCtx.lineWidth = 2;
|
||||||
canvasCtx.strokeStyle = '#1E90FF';
|
canvasCtx.strokeStyle = '#0d6efd'; // Primary button color
|
||||||
canvasCtx.beginPath();
|
canvasCtx.beginPath();
|
||||||
const sliceWidth = waveformCanvas.width * 1.0 / bufferLength;
|
const sliceWidth = waveformCanvas.width * 1.0 / bufferLength;
|
||||||
let x = 0;
|
let x = 0;
|
||||||
@ -109,7 +113,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
mediaRecorder.onstop = () => {
|
mediaRecorder.onstop = () => {
|
||||||
console.log('MediaRecorder stopped and onstop event fired.');
|
console.log('MediaRecorder stopped and onstop event fired.');
|
||||||
// Stop all tracks on the stream to release the microphone
|
|
||||||
if (streamReference) {
|
if (streamReference) {
|
||||||
streamReference.getTracks().forEach(track => track.stop());
|
streamReference.getTracks().forEach(track => track.stop());
|
||||||
console.log('Microphone stream tracks stopped.');
|
console.log('Microphone stream tracks stopped.');
|
||||||
@ -176,7 +179,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
saveRecordBtn.style.display = 'none';
|
saveRecordBtn.style.display = 'none';
|
||||||
loadRecordings();
|
loadRecordings();
|
||||||
} else {
|
} else {
|
||||||
// Use the error from the JSON if available, otherwise a generic message
|
|
||||||
const errorMessage = data.error || 'An unknown error occurred.';
|
const errorMessage = data.error || 'An unknown error occurred.';
|
||||||
alert('Error saving recording: ' + errorMessage);
|
alert('Error saving recording: ' + errorMessage);
|
||||||
console.error('Server-side save error:', errorMessage);
|
console.error('Server-side save error:', errorMessage);
|
||||||
@ -189,4 +191,4 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
loadRecordings();
|
loadRecordings();
|
||||||
});
|
});
|
||||||
|
|||||||
BIN
assets/pasted-20250923-214203-80d8873e.png
Normal file
BIN
assets/pasted-20250923-214203-80d8873e.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 534 KiB |
82
index.php
82
index.php
@ -7,67 +7,61 @@
|
|||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
<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.googleapis.com">
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
|
||||||
<link href="assets/css/custom.css" 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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<header class="p-3 bg-dark text-white text-center">
|
<header class="p-3 mb-4 text-center">
|
||||||
<h1>Audio Recorder & Visualizer</h1>
|
<h1 class="display-5">Audio Recorder</h1>
|
||||||
|
<p class="lead text-muted">Record, visualize, and save your audio with ease.</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="container my-5">
|
<div class="container-fluid px-4">
|
||||||
<div class="hero p-5 text-center bg-image" style="background-image: url('https://picsum.photos/seed/wave/1200/400'); border-radius: 0.5rem;">
|
<div class="row g-4">
|
||||||
<div class="mask" style="background-color: rgba(0, 0, 0, 0.6);">
|
<!-- Left Column: Recorder -->
|
||||||
<div class="d-flex justify-content-center align-items-center h-100">
|
<div class="col-lg-7">
|
||||||
<div class="text-white">
|
<div class="card shadow-sm h-100">
|
||||||
<h1 class="mb-3">Record and Visualize Your Audio</h1>
|
<div class="card-body d-flex flex-column">
|
||||||
<p class="mb-3">Click the button below to start recording your microphone and see the audio visualized in real-time.</p>
|
<h5 class="card-title mb-3">Recorder</h5>
|
||||||
<button id="startRecordBtn" class="btn btn-primary btn-lg">Start Recording</button>
|
<div class="flex-grow-1 d-flex align-items-center justify-content-center bg-light rounded p-3">
|
||||||
<button id="stopRecordBtn" class="btn btn-danger btn-lg" disabled>Stop Recording</button>
|
<canvas id="waveform"></canvas>
|
||||||
<button id="saveRecordBtn" class="btn btn-success btn-lg" style="display: none;">Save Recording</button>
|
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row mt-5">
|
<!-- Right Column: Library -->
|
||||||
<div class="col-md-8 offset-md-2">
|
<div class="col-lg-5">
|
||||||
<div class="card">
|
<div class="card shadow-sm h-100">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title text-center">Live Audio Waveform</h5>
|
<h5 class="card-title mb-3">Library</h5>
|
||||||
<canvas id="waveform"></canvas>
|
<div id="recordingsList" class="overflow-auto" style="max-height: 400px;">
|
||||||
|
<!-- Recordings will be loaded here -->
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row mt-5">
|
|
||||||
<div class="col-md-8 offset-md-2">
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-body">
|
|
||||||
<h5 class="card-title text-center">Saved Recordings</h5>
|
|
||||||
<div id="recordingsList"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row mt-5 text-center">
|
|
||||||
<div class="col-md-6">
|
|
||||||
<img src="https://picsum.photos/seed/record/600/400" class="img-fluid rounded" alt="A modern microphone in a recording studio.">
|
|
||||||
</div>
|
|
||||||
<div class="col-md-6">
|
|
||||||
<img src="https://picsum.photos/seed/gallery/600/400" class="img-fluid rounded" alt="A collection of audio waveforms.">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer class="p-3 bg-dark text-white text-center mt-5">
|
<footer class="text-center text-muted mt-5 pb-3">
|
||||||
<p>© 2025 Audio Recorder & Visualizer</p>
|
<p>© 2025 Audio Recorder. All Rights Reserved.</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<script src="assets/js/main.js"></script>
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@ -6,35 +6,71 @@ $response = [];
|
|||||||
// The directory where recordings will be stored.
|
// The directory where recordings will be stored.
|
||||||
$uploadDir = 'uploads/';
|
$uploadDir = 'uploads/';
|
||||||
|
|
||||||
// Ensure the upload directory exists and is writable.
|
// Check if the upload directory exists and is writable.
|
||||||
if (!is_dir($uploadDir)) {
|
if (!is_dir($uploadDir)) {
|
||||||
|
// Try to create it if it doesn't exist.
|
||||||
if (!mkdir($uploadDir, 0775, true)) {
|
if (!mkdir($uploadDir, 0775, true)) {
|
||||||
$response = ['success' => false, 'message' => 'Failed to create upload directory.'];
|
$response = ['success' => false, 'error' => 'Server error: Cannot create upload directory.'];
|
||||||
echo json_encode($response);
|
echo json_encode($response);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the raw POST data.
|
if (!is_writable($uploadDir)) {
|
||||||
$audioData = file_get_contents('php://input');
|
$response = ['success' => false, 'error' => 'Server error: The uploads directory is not writable. Please check file permissions.'];
|
||||||
|
echo json_encode($response);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
if ($audioData) {
|
// Check if a file was uploaded and there are no errors.
|
||||||
// Generate a unique filename.
|
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';
|
$fileName = 'recording_' . date('Y-m-d_H-i-s') . '_' . uniqid() . '.wav';
|
||||||
$filePath = $uploadDir . $fileName;
|
$filePath = $uploadDir . $fileName;
|
||||||
|
|
||||||
// Save the file.
|
// Move the uploaded file from the temporary directory to the final destination.
|
||||||
if (file_put_contents($filePath, $audioData)) {
|
if (move_uploaded_file($tmpName, $filePath)) {
|
||||||
$response['success'] = true;
|
$response['success'] = true;
|
||||||
$response['message'] = 'Audio saved successfully.';
|
$response['message'] = 'Audio saved successfully.';
|
||||||
$response['file_path'] = $filePath;
|
$response['file_path'] = $filePath;
|
||||||
} else {
|
} else {
|
||||||
$response['success'] = false;
|
$response['success'] = false;
|
||||||
$response['message'] = 'Error saving audio file. Check directory permissions.';
|
$response['error'] = 'Error saving audio file after upload. Check directory permissions.';
|
||||||
}
|
}
|
||||||
} else {
|
} 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['success'] = false;
|
||||||
$response['message'] = 'No audio data received.';
|
$response['error'] = $error_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo json_encode($response);
|
echo json_encode($response);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user