<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jim Miller</title>
    <description>The latest articles on DEV Community by Jim Miller (@jimmiller27).</description>
    <link>https://dev.to/jimmiller27</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4273724%2F00092caa-66aa-46b0-8053-912d92da445a.png</url>
      <title>DEV Community: Jim Miller</title>
      <link>https://dev.to/jimmiller27</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jimmiller27"/>
    <language>en</language>
    <item>
      <title>Finding a song's BPM and key in the browser, with no libraries</title>
      <dc:creator>Jim Miller</dc:creator>
      <pubDate>Mon, 30 Nov 2026 11:29:04 +0000</pubDate>
      <link>https://dev.to/jimmiller27/finding-a-songs-bpm-and-key-in-the-browser-with-no-libraries-5g0m</link>
      <guid>https://dev.to/jimmiller27/finding-a-songs-bpm-and-key-in-the-browser-with-no-libraries-5g0m</guid>
      <description>&lt;p&gt;I needed a tool that tells you the tempo and key of a song file without uploading it anywhere. Everything below runs in the browser: the Web Audio API decodes the file, and about 100 lines of plain JavaScript do the rest. No TensorFlow, no WASM, no server.&lt;/p&gt;

&lt;p&gt;You can try the finished version here: &lt;a href="https://musicbun.com/bpm-and-key-finder" rel="noopener noreferrer"&gt;free BPM and key finder&lt;/a&gt;. Drop in an MP3 and it shows the BPM, the key and its Camelot code in a few seconds.&lt;/p&gt;

&lt;p&gt;Here is how it works.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Decode and shrink the audio
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;AudioContext.decodeAudioData&lt;/code&gt; turns any file the browser can play (MP3, WAV, M4A, OGG, FLAC) into raw samples. Two things make the rest much faster:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mix all channels down to mono.&lt;/li&gt;
&lt;li&gt;Downsample to about 11 kHz by averaging groups of samples. Beats and notes up to 2 kHz survive, and there are four times fewer samples to process.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mono&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ab&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ab&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sampleRate&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;11025&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ab&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sampleRate&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ab&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ab&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sampleRate&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;240&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// first 4 minutes&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Float32Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;ab&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;numberOfChannels&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ab&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getChannelData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;ab&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;numberOfChannels&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sr&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Tempo: find the hits, then the grid that fits them
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Onsets.&lt;/strong&gt; Slice the audio into short overlapping windows (512 samples, hop 128), run an FFT on each, and add up how much each frequency bin got &lt;em&gt;louder&lt;/em&gt; than in the previous window. That sum is called spectral flux. It spikes on drum hits and note attacks and stays low on held notes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;N&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log1p&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hypot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;im&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// compressed magnitude&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// only count increases&lt;/span&gt;
  &lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The log compression matters: without it, one loud kick drum hides everything else.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remove the swell.&lt;/strong&gt; Songs get louder and quieter over whole sections. Subtracting a moving average of about one second leaves only the sharp hits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Autocorrelation.&lt;/strong&gt; If a song is at 120 BPM, the hits repeat every 0.5 seconds, so the onset curve lines up with a copy of itself shifted by 0.5 seconds. Compute that match for every shift up to 16 beats at 60 BPM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pick the tempo.&lt;/strong&gt; For each candidate from 60 to 200 BPM, score the match at 1, 2, 3 and 4 beats, weighted 1, 0.6, 0.4 and 0.3. Then multiply by a gentle preference for tempos near 120 (a log-normal curve), because most popular music sits around there.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Half or double time.&lt;/strong&gt; This is where most BPM detectors disagree with humans. Is that hip-hop track 85 or 170? Two checks help:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the in-between beats hit almost as hard as the beats themselves, the real tempo is double.&lt;/li&gt;
&lt;li&gt;If every other beat is weak, the real tempo is half.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tool still shows half and double time under the result, because sometimes both answers are fair.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fine tune.&lt;/strong&gt; Finally, search ±1.5 BPM in steps of 0.01 and line up 16 beats at once. Small errors add up over 16 beats, so this pins the tempo to a fraction of a BPM.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Key: count the notes, compare with 24 profiles
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Chroma.&lt;/strong&gt; Use bigger windows this time (4096 samples), because you need fine frequency detail to tell C from C♯. Map every FFT bin between 55 Hz and 2 kHz to one of the 12 note names:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;freq&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;440&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;69&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add up the energy of each note name over the whole song, normalising each window so loud parts do not dominate. You end up with 12 numbers: how much C, C♯, D … B the song uses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key profiles.&lt;/strong&gt; Krumhansl and Kessler measured how well each note "fits" in a major and a minor key. Their two profiles, rotated to all 12 starting notes, give 24 templates. The key is the template with the highest Pearson correlation with the song's chroma.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MAJ&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;6.35&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;3.48&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.33&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;4.38&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;4.09&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.52&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;5.19&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.39&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;3.66&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.29&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.88&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MIN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;6.33&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.68&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;3.52&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;5.38&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;3.53&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.54&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;4.75&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;3.98&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.69&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;3.34&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;3.17&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;C major and A minor use the same notes, so they often score close together. That is why the tool also shows the next closest key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Camelot code.&lt;/strong&gt; DJs write keys on the Camelot wheel (1A to 12B), where neighbours mix well. Converting is one line once you see that the wheel walks in fifths:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;camelot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="sb"&gt;`${((((minor ? pc + 3 : pc) % 12) * 7 + 7) % 12) + 1}${minor ? "A" : "B"}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Keep the page responsive
&lt;/h2&gt;

&lt;p&gt;A four-minute song means tens of thousands of FFTs. Every 2,000 frames the loop does &lt;code&gt;await new Promise(r =&amp;gt; setTimeout(r))&lt;/code&gt; and updates a progress bar, so the page never freezes. No Web Worker needed for this size.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Simple DSP goes a long way. Spectral flux plus autocorrelation gets the tempo right for most songs with a steady beat.&lt;/li&gt;
&lt;li&gt;Half/double time is a judgement call, not a bug. Show both.&lt;/li&gt;
&lt;li&gt;Key detection is weakest on songs that change key or barely use harmony (a solo drum track has no key). Say so instead of guessing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to try it on your own tracks, the &lt;a href="https://musicbun.com/bpm-and-key-finder" rel="noopener noreferrer"&gt;BPM and key finder&lt;/a&gt; is free and the file never leaves your device. To practise at the tempo you found, there is also an &lt;a href="https://musicbun.com/online-metronome" rel="noopener noreferrer"&gt;online metronome&lt;/a&gt; built on the same Web Audio clock.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webaudio</category>
      <category>music</category>
      <category>dsp</category>
    </item>
    <item>
      <title>Make a short instrumental intro for your project demo with a chat-based AI music tool</title>
      <dc:creator>Jim Miller</dc:creator>
      <pubDate>Mon, 30 Nov 2026 08:32:59 +0000</pubDate>
      <link>https://dev.to/jimmiller27/make-a-short-instrumental-intro-for-your-project-demo-with-a-chat-based-ai-music-tool-khb</link>
      <guid>https://dev.to/jimmiller27/make-a-short-instrumental-intro-for-your-project-demo-with-a-chat-based-ai-music-tool-khb</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Disclosure:&lt;/strong&gt; I work on growth at MusicBun, the tool used in this walkthrough. The project, prompts, and listening checklist below are examples written for this post, not results from a generation I ran.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Your side project has a working demo, a screen recording, and an opening card. What's missing is a short instrumental theme that can sit under the intro without fighting the narration. Before reaching for another production tool, you need a clear musical brief.&lt;/p&gt;

&lt;p&gt;This walkthrough uses MusicBun to turn that brief into an editable draft, fix the draft before spending credits, and generate two versions to compare. The running example is a fictional project called &lt;strong&gt;Patch Notes&lt;/strong&gt;, a tool that turns development updates into a readable changelog.&lt;/p&gt;

&lt;p&gt;One thing to decide up front: &lt;strong&gt;songs made with free monthly credits are for playing and sharing only.&lt;/strong&gt; If the music will go into a commercial demo, podcast, ad, or game, make it on a paid plan or with extra credits. Upgrading later does not change the license of a song you already made with free monthly credits.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Write the brief around the opening scene
&lt;/h2&gt;

&lt;p&gt;Start at &lt;a href="https://musicbun.com/ai-jingle-maker" rel="noopener noreferrer"&gt;https://musicbun.com/ai-jingle-maker&lt;/a&gt; or the main chat at &lt;a href="https://musicbun.com/" rel="noopener noreferrer"&gt;https://musicbun.com/&lt;/a&gt;. Both open the same chat workflow, just from a different starting point. The interface is in English.&lt;/p&gt;

&lt;p&gt;Before typing, decide what job the music does. Here, the opening card introduces the project and then hands off to a narrated walkthrough. That points to a simple melody, light percussion, and no vocals. A busy arrangement would compete with what you want viewers to hear.&lt;/p&gt;

&lt;p&gt;An example prompt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create a short instrumental theme for Patch Notes, a small developer
tool that turns project updates into a readable changelog. Imagine
opening the demo on a calm Monday morning: a clean screen, one new
release, and a clear next step. Use warm synths, a simple plucked
melody, and light percussion, around 100 BPM. No vocals. Aim for
roughly 20 seconds, with a clear opening and a gentle ending that
can lead into spoken narration. Keep the mood curious and focused.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the structure: what it's for, a concrete scene, then the sound in a few words (instruments, tempo, voice). "Innovative music for developers" gives the model almost nothing to work with; "warm synths, sparse plucked melody, light percussion" does.&lt;/p&gt;

&lt;p&gt;Treat "around 100 BPM" and "roughly 20 seconds" as creative direction, not guaranteed properties of the output. Don't cut your video to a length you've only requested; wait until you have audio.&lt;/p&gt;

&lt;p&gt;If what you really need is a backing loop rather than a theme, &lt;a href="https://musicbun.com/ai-beat-maker" rel="noopener noreferrer"&gt;https://musicbun.com/ai-beat-maker&lt;/a&gt; is set up for instrumentals and you can name a tempo and key there too. You don't need to try every generator to finish this one intro.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Review the draft before any audio is made
&lt;/h2&gt;

&lt;p&gt;MusicBun answers with a draft first: a title, a style, and lyrics. You can edit any of it before anything is generated. &lt;strong&gt;Chatting and editing the draft use no credits.&lt;/strong&gt; Only making the audio does.&lt;/p&gt;

&lt;p&gt;For an instrumental, check two things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Voice:&lt;/strong&gt; set it to &lt;strong&gt;No vocals&lt;/strong&gt;. The voice options are male, female, or no vocals.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lyrics/style:&lt;/strong&gt; if the draft still reads like a sung song, say so. The project name belongs in the brief as context; it doesn't need to become a hook.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Change one thing at a time so you can see what each instruction did. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Keep this instrumental, with No vocals. Make the arrangement less
busy: one plucked melody, a warm synth layer, and light percussion.
Keep the ending gentle so narration can follow it.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read the revised draft again. This is the cheap place to catch an unwanted singer, an overblown mood, or a style that has drifted away from what the project is.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Generate once, then listen to both versions
&lt;/h2&gt;

&lt;p&gt;When the draft looks right, make the song. You'll need to sign in at this step. One generation costs &lt;strong&gt;2 credits and gives you two versions&lt;/strong&gt;, instrumentals included, so you get a pair to compare from a single run.&lt;/p&gt;

&lt;p&gt;Free accounts get 3 credits a month, which covers one generation (two versions). If a generation fails, the credits come back automatically.&lt;/p&gt;

&lt;p&gt;Listen to both versions all the way through before you pick one, and judge them against the same brief:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does the opening suit a small, practical tool?&lt;/li&gt;
&lt;li&gt;Could the melody sit under speech without taking over?&lt;/li&gt;
&lt;li&gt;Does the ending hand off cleanly to the walkthrough?&lt;/li&gt;
&lt;li&gt;Does the actual length fit the slot in your video?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Write down &lt;em&gt;why&lt;/em&gt;, not just which one. A note like "A: opening too busy / B: ending stops abruptly" tells you what to change next; "B is better" doesn't.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Fix one specific mismatch
&lt;/h2&gt;

&lt;p&gt;If neither version fits, name the single biggest problem before touching the prompt. Generic-sounding? Put a more specific scene back in. Competing with the voiceover? Ask for fewer elements. Changing tempo, genre, instruments, and mood all at once makes it impossible to tell which change helped.&lt;/p&gt;

&lt;p&gt;A follow-up might be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Revise the draft toward a quieter opening for a spoken demo.
Keep the warm synths and plucked melody, but reduce the percussion
and avoid a dramatic build. Keep No vocals.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Editing the draft is still free. Generating a new pair costs another 2 credits, so treat each new generation as a deliberate decision, and check which credits you're using if the result is headed for a commercial video.&lt;/p&gt;

&lt;p&gt;Once you have a candidate you're licensed to use, drop it under your real narration in your usual video editor. That placement test tells you more than listening to the music alone. Trimming and level adjustments happen in your editor; they're not part of MusicBun.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Check the license before it goes in the demo
&lt;/h2&gt;

&lt;p&gt;What you can do with a song depends on the credits used to make it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Free monthly credits:&lt;/strong&gt; play and share only. No commercial use, and download isn't included.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Paid plan or extra credits:&lt;/strong&gt; you can download the song, and it comes with a royalty-free commercial license covering uses like videos, podcasts, ads, and games.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Buying a plan later does not retroactively license a free-credit version you liked, so decide on commercial use &lt;em&gt;before&lt;/em&gt; generating the version you plan to publish. Terms: &lt;a href="https://musicbun.com/license" rel="noopener noreferrer"&gt;https://musicbun.com/license&lt;/a&gt;. Plans and credit packs: &lt;a href="https://musicbun.com/pricing" rel="noopener noreferrer"&gt;https://musicbun.com/pricing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Songs stay private until you share a link. Sending a link to a collaborator for feedback is a separate decision from putting the track in a commercial video.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you end up with
&lt;/h2&gt;

&lt;p&gt;One intro theme that fits one specific opening, plus a written reason for choosing it. Keep the brief and your listening notes in the project repo or docs. Next time you need a revision, you'll start from a concrete requirement instead of another vague request for "tech music."&lt;/p&gt;




&lt;p&gt;Jim Miller, Growth at MusicBun · &lt;a href="https://musicbun.com/" rel="noopener noreferrer"&gt;https://musicbun.com/&lt;/a&gt; · Contact: &lt;a href="mailto:hello@musicbun.com"&gt;hello@musicbun.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdfk4f2hk19frpuni298o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdfk4f2hk19frpuni298o.png" alt="Official-site example draft: “A birthday song for my sister Mia, upbeat pop”" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Draft screenshot: the official-site example “A birthday song for my sister Mia, upbeat pop”.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5g6cc7breblivrg22hpi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5g6cc7breblivrg22hpi.png" alt="Free plan and one-time credit packs, screenshot 2026-11-30" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Free plan and one-time credit packs (screenshot, 2026-11-30).&lt;/em&gt;&lt;/p&gt;

</description>
      <category>music</category>
      <category>ai</category>
      <category>tutorial</category>
      <category>sideprojects</category>
    </item>
  </channel>
</rss>
