Web Audio API
How do I make an web audio api?
AudioContext render. What is a web audio api? How do you make a web audio api? This script and codes were developed by Dima on 17 September 2022, Saturday.
Web Audio API - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>web Audio API</title> <link href='https://fonts.googleapis.com/css?family=Indie+Flower' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<svg width="100%" height="100%"> <circle cx="10%" cy="100" r="20" fill="#FDD2B5" opacity="0.3"> <animate attributename="r" from="0" to="1000" dur="2s" repeatcount="indefinite"></animate> </circle> <circle cx="90%" cy="100" r="20" fill="#9DF1E3" opacity="0.3"> <animate attributename="r" from="0" to="1000" dur="2s" begin="1s" repeatcount="indefinite"></animate> </circle>
</svg>
<div class="intro"> <canvas class="top"></canvas> <h1> Orange<br/>summer</h1> <p> orange mood</p> <canvas class="bottom"></canvas>
</div>
<audio preload="" autoplay="" loop="" src="//zupra.github.io/test/audio/lose_yourself_to_dance.mp3" crossorigin="Anonymous"> <!--src='https://s3.amazonaws.com/uploads.hipchat.com/78163/574822/Nkrpb6ipAMmfmNU/beats.ogg'-->
</audio> <script src="js/index.js"></script>
</body>
</html>
Web Audio API - Script Codes CSS Codes
* { margin: 0; padding: 0; box-sizing: border-box;
}
body { height: 100vh; font-family: 'Indie Flower', cursive; font-size: calc(1vw + 1vh);
}
svg { position: absolute; z-index: -1;
}
canvas { position: absolute;
}
canvas.top { top: 0; z-index: -2; width: 300px; height: 150px;
}
canvas.bottom { bottom: 0;
}
.intro { margin: auto; font-size: 3em; color: #ff7f50; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 0 2em;
}
.intro h1 { line-height: 1;
}
Web Audio API - Script Codes JS Codes
//Safary
var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioContext = new AudioContext();
var audio = document.getElementsByTagName('audio')[0];
var source = audioContext.createMediaElementSource(audio);
var analyser = audioContext.createAnalyser();
source.connect(analyser);
source.connect(audioContext.destination);
analyser.fftSize = 1024;
var bufferLength = analyser.frequencyBinCount;
//- var dataArray = new Uint8Array(bufferLength);
var frequencyData = new Uint8Array(bufferLength);
function Render() { var canvas = document.getElementsByTagName('canvas')[0]; var canvasContext = canvas.getContext('2d'); var WIDTH = canvas.width; var HEIGHT = canvas.height; function draw() { requestAnimationFrame(draw); analyser.getByteTimeDomainData(frequencyData); canvasContext.fillStyle = '#FFF'; canvasContext.fillRect(0, 0, WIDTH, HEIGHT); canvasContext.lineWidth = 1; canvasContext.strokeStyle = '#222'; canvasContext.beginPath(); var sliceWidth = WIDTH * .8 / bufferLength; var x = 0; for (var i = 0; i < bufferLength; i++) { var v = frequencyData[i] / 16; var y = v * HEIGHT / 16; if (i === 0) { canvasContext.moveTo(x, 75); x = WIDTH / 9; } else { canvasContext.lineTo(x, y); } x += sliceWidth; } canvasContext.lineTo(canvas.width, canvas.height / 2); canvasContext.stroke(); } draw();
}
function Render2() { var canvas = document.getElementsByTagName('canvas')[1]; var canvasContext = canvas.getContext('2d'); canvas.width = window.innerWidth; canvas.height = window.innerHeight / 2; window.addEventListener('resize', function() { canvas.width = window.innerWidth; canvas.height = window.innerHeight / 2; }); function draw2() { requestAnimationFrame(draw2); canvasContext.clearRect(0, 0, canvas.width, canvas.height); analyser.getByteFrequencyData(frequencyData); var frequencyWidth = (canvas.width / bufferLength), frequencyHeight = 0, x = 0; for (var increment = 0; increment < bufferLength; increment++) { frequencyHeight = frequencyData[increment] * (canvas.height * 0.003); canvasContext.fillStyle = 'khaki'; //'rgb(255, 120, 120)'; canvasContext.fillRect(x, canvas.height - frequencyHeight, frequencyWidth, frequencyHeight); x += frequencyWidth + 3; } } draw2();
}
audio.addEventListener('playing', function() { Render(); Render2();
}, false);
Developer | Dima |
Username | dimaZubkov |
Uploaded | September 17, 2022 |
Rating | 4 |
Size | 3,946 Kb |
Views | 28,336 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Vue radio | 5,915 Kb |
Price range slider | 3,589 Kb |
Glitch | 3,368 Kb |
Ken Burns Effect | 3,067 Kb |
Fluid typography | 3,929 Kb |
Glitch | 2,843 Kb |
Section Slides | 5,312 Kb |
Audio button | 2,784 Kb |
Mega menu | 5,066 Kb |
Angular T-shirt shop | 8,889 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Lightrays v2 | Sinthetyc | 2,903 Kb |
Pagepilling.js | Blossk | 6,554 Kb |
CSS-Flexbox-Demo | Sstiglets | 1,709 Kb |
IE11 Test | Boostnewmedia | 4,998 Kb |
Css Rotating 3d cubes different speed | Dghez | 2,364 Kb |
ECharts Version 3.0 - Bar Marker Chart | WebCodePro | 2,726 Kb |
RSW | JordanC | 3,726 Kb |
A Pen by Jay | Jaycode | 3,784 Kb |
FreeCodeCamp - Simon Game | Ivhed | 8,481 Kb |
700 Synapses Per Second | Silentkrange | 2,138 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!