Sound Visualizer
Info
Created On: August 1, 2023
Created By:
AI
Model: gpt-3.5-turbo-16k-0613
Time: 20 seconds
Prompt Tokens: 817
Completion Tokens: 683
Total Token Cost: 1500
Get This App On Your Website
Copy Code
1. Copy the code above with the iframe and link.
2. Paste the code into your website.
3. Resize the iframe to fit your website.
Javascript, HTML, CSS Code
Copy
<html>
<head>
<script type="text/javascript"> window.addEventListener('error', function(event) { var message = JSON.parse(JSON.stringify(event.message)); var source = event.filename; var lineno = event.lineno; var colno = event.colno; var error = event.error; window.parent.postMessage({ type: 'iframeError', details: { message: message, source: source, lineno: lineno, colno: colno, error: error ? error.stack : '' } }, '*'); }); window.addEventListener('unhandledrejection', function(event) { window.parent.postMessage({ type: 'iframePromiseRejection', details: { reason: event.reason } }, '*'); }); </script>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Sound Visualizer</title>
<meta name="description" content="A fun app that visualizes the computer sound output">
<meta name="keywords" content="sound, visualizer, bass, treble">
<!-- External Dependencies -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- App CSS -->
<style>
body {
background: #111111;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.visualizer {
width: 500px;
height: 300px;
border: 1px solid #ffffff;
padding: 10px;
border-radius: 10px;
background: linear-gradient(to right, #005eff, #ff00f7);
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
}
.bars {
display: flex;
justify-content: space-between;
align-items: flex-end;
height: 100%;
padding: 0 5px;
}
.bar {
width: 10px;
background: #ffffff;
border-radius: 5px 5px 0 0;
transition: height 0.2s ease;
}
</style>
<link rel="canonical" href="https://calculator.tools/prompt/2906/">
<meta charset="utf-8">
</head>
<body>
<div id="main-container" class="container">
<div class="visualizer">
<div class="bars"></div>
</div>
</div>
<!-- App JavaScript -->
<script>
// Get audio context
const AudioContext = window.AudioContext || window.webkitAudioContext;
const audioContext = new AudioContext();
// Create analyser node
const analyserNode = audioContext.createAnalyser();
analyserNode.fftSize = 256;
// Create array to store frequency data
const dataArray = new Uint8Array(analyserNode.frequencyBinCount);
// Connect audio context to the destination (output)
audioContext.destination.connect(analyserNode);
// Function to update the visualizer
function updateVisualizer() {
// Get current frequency data
analyserNode.getByteFrequencyData(dataArray);
// Clear previous bars
const barsContainer = document.querySelector('.bars');
barsContainer.innerHTML = '';
// Create new bars based on frequency data
for (let i = 0; i < dataArray.length; i++) {
const barHeight = dataArray[i];
const barElement = document.createElement('div');
barElement.classList.add('bar');
barElement.style.height = `${barHeight}px`;
barsContainer.appendChild(barElement);
}
// Call the function again on the next animation frame
requestAnimationFrame(updateVisualizer);
}
// Start visualizer
updateVisualizer();
</script>
<script type="text/javascript"> var localStoragePrefix = "ct-{{ cachebreaker }}"; var lastSave = 0; function saveLocal(data) { if (Date.now() - lastSave < 1000) { return; } let cookie = localStoragePrefix + "=" + JSON.stringify(data) + "; path=" + window.location.pathname + "'; SameSite=Strict"; cookie += "; expires=" + new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 * 1000).toUTCString(); document.cookie = cookie; lastSave = Date.now(); } function loadLocal() { var cookiePrefix = localStoragePrefix + "="; var cookieStart = document.cookie.indexOf(cookiePrefix); if (cookieStart > -1) { let cookieEnd = document.cookie.indexOf(";", cookieStart); if (cookieEnd == -1) { cookieEnd = document.cookie.length; } var cookieData = document.cookie.substring(cookieStart + cookiePrefix.length, cookieEnd); return JSON.parse(cookieData); } } </script>
<script type="text/javascript"> window.addEventListener('load', function() { var observer = new MutationObserver(function() { window.parent.postMessage({height: document.documentElement.scrollHeight || document.body.scrollHeight},"*"); }); observer.observe(document.body, {attributes: true, childList: true, subtree: true}); window.parent.postMessage({height: document.documentElement.scrollHeight || document.body.scrollHeight},"*"); }); </script>
</body>
</html>