-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
index.html
76 lines (73 loc) · 3.6 KB
/
index.html
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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Finding out the BPM of a song using Javascript</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="description" content="Demo of an algorithm to calculate tempo of a track using the Audio API, using the Spotify Web API to search for songs.">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@jmperezperez">
<meta name="twitter:title" content="Finding out the BPM of a song on a browser">
<meta name="twitter:description" content="Demo of an algorithm to calculate tempo of a track using the Audio API, using the Spotify Web API to search for songs.">
<link rel="author" href="https://plus.google.com/107456024651797783420" />
<link rel="canonical" href="https://jmperezperez.com/beats-audio-api/" />
</head>
<body>
<script type="text/javascript">
var _gaq=_gaq||[];_gaq.push(["_setAccount","UA-39254352-1"]);_gaq.push(["_trackPageview"]);(function(){var a=document.createElement("script");a.type="text/javascript";a.async=!0;a.src="https://www.google-analytics.com/ga.js";var b=document.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b)})()
</script>
<h1>Calculating BPM using Javascript and the Spotify Web API</h1>
<p>This demo uses the browser's <strong>Audio API</strong> to determine the tempo of a song, processing a chunk of 30 seconds of a song.</p>
<p>For more information, read the blog post <a href="http://joesul.li/van/beat-detection-using-web-audio/">Beat Detection Using JavaScript and the Web Audio API</a>, from where I've taken the code to perform the track analysis,
and <a href="https://jmperezperez.com/bpm-detection-javascript/">my blog post</a> where I explain some changes I made to
the original algorithm and how I used Spotify's APIs to find and match tracks.
</p>
<form>
<input type="text" id="query" placeholder="Type the name of a track (e.g. Beyonce - Baby Boy)">
<input type="submit" value="Search track & Calculate tempo">
</form>
<div id="result">
<div id="text"></div>
<div>
<svg width="100%" height="40" id="svg"></svg>
<button id="play">Play track</button>
</div>
<audio id="audio"></audio>
</div>
<p>How this works:</p>
<ol>
<li>Search for the track on <a href="https://developer.spotify.com/web-api/search-item/">Spotify using their Web API</a></li>
<li>Use the 30s preview MP3 as the source for the Audio API</li>
<li>Apply a lowbass filter</li>
<li>Find peaks</li>
<li>Count intervals between peaks</li>
<li>Group them</li>
</ol>
<footer>
<h3>Source Code</h3>
<p>You can <a href="https://github.com/JMPerez/beats-audio-api">check out the code on GitHub</a>.</p>
</footer>
<footer class="about">
<h3>About me</h3>
<div class="media">
<div class="img">
<img src="https://jmperezperez.com/assets/images/jmperez.jpg" class="avatar-image" title="José M. Pérez">
</div>
<div class="bd">
<div class="name">José M. Pérez</div>
<div class="media twitter">
<div class="img">
<img src="https://jmperezperez.com/assets/images/twitter.svg" width="16" height="16" class="twitter-logo" alt="Twitter">
</div>
<div class="bd">
<a href="https://twitter.com/jmperezperez">@jmperezperez</a>
</div>
</div>
<a href="https://jmperezperez.com">jmperezperez.com</a>
</div>
</div>
</footer>
<script src="spotify-web-api.js"></script>
<script src="script.js"></script>
</body>
</html>