Spaces:
Sleeping
Sleeping
File size: 3,513 Bytes
13a4f5e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
<!DOCTYPE html> <html> <head> <title>Mood-Based Music Recommendation</title> <style> /* Your existing CSS styles here */ body { font-family: Arial, sans-serif; background-color: #f2f2f2; margin: 0; padding: 0; } .container { display: flex; justify-content: center; align-items: center; height: 100vh; } .prompt { background-color: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); text-align: center; } button { background-color: #4CAF50; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; margin: 10px; } button:hover { background-color: #45a049; } </style> </head> <body> <div class="container"> <div class="prompt"> <!-- Audio prompt --> <audio controls autoplay id="audioPrompt"> <source src="how_are_you_feeling_today.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio> <button id="startBtn" onclick="startRecording()">Start Recording</button> <button id="stopBtn" onclick="stopRecording()" disabled>Stop Recording</button> </div> </div> <script> let mediaRecorder; let recordedChunks = []; function startRecording() { navigator.mediaDevices.getUserMedia({ audio: true }) .then(function (stream) { mediaRecorder = new MediaRecorder(stream); mediaRecorder.ondataavailable = function (event) { recordedChunks.push(event.data); }; mediaRecorder.onstop = function () { const audioBlob = new Blob(recordedChunks, { type: 'audio/mp3' }); // Create a download link to save the audio recording const downloadLink = document.createElement('a'); downloadLink.href = URL.createObjectURL(audioBlob); downloadLink.download = 'recorded_audio.mp3'; downloadLink.click(); // Reset the recordedChunks for the next recording recordedChunks = []; }; mediaRecorder.start(); document.getElementById("startBtn").disabled = true; document.getElementById("stopBtn").disabled = false; // Pause the audio prompt while recording const audioPrompt = document.getElementById("audioPrompt"); audioPrompt.pause(); }) .catch(function (err) { console.log("Error accessing microphone:", err); }); } function stopRecording() { mediaRecorder.stop(); document.getElementById("startBtn").disabled = false; document.getElementById("stopBtn").disabled = true; // Resume the audio prompt after recording const audioPrompt = document.getElementById("audioPrompt"); audioPrompt.play(); } </script> </body> </html> |