cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <main>
  
  <h1>Audio player with tempo adjustment</h1>
  <p>Maintains pitch while slowing an MP3 down.<br>For beginner guitarists, like myself, to practice chord progressions at a managable pace.</p>
  
  <div class=group>
    
    <h2>Audio source (.mp3)</h2>

    <div class=url>
      <label class=url_label for=url_input><span>Address</span></label>
      <input id=url_input class=url_input type=url value="https://websemantics.uk/pens/audio-tempo-change-fixed-pitch/media/hard-days-night.mp3">
    </div>

    <p>OR</p>

    <div class=upload>
      <label class=upload_label for=upload_input><span>Upload</span></label>
      <input id=upload_input class=upload_input type=file accept="audio/*">
    </div>

  </div>
  
  <div class=group>
  
    <div class=player>
      <h3 class=player_display></h3>
      <audio class=player_audio controls>
        <track id=player-chords kind=captions srclang=en>
      </audio>
    </div>

    <div class=tempo>
      <label class=tempo_label for=tempo_input>Tempo</label>
      <input class=tempo_input id=tempo_input type=range value=0.825 min=0.5 max=1 step=0.025>
      <span class=tempo_display></span>
    </div>
    
  </div>
  
</main>


<footer class=myStuff><style>.myStuff{z-index:10;font-weight:100;color:#777;font-size:16px;position:fixed;width:100vw;left:0;bottom:0;margin:0;background-color:hsla(269,19%,20%,.9);padding:.125em;line-height:1.5;text-align:center}.myStuff_lnk,.myStuff_lnk:visited{text-decoration-skip: ink;color:hsla(211,100%,72%,1);text-decoration-color:hsla(211,100%,72%,.5);transition:all .3s ease-out;white-space:nowrap}.myStuff_lnk:focus,.myStuff_lnk:hover{color:#fff;text-decoration-color:currentcolor}</style><a class=myStuff_lnk target=linkedin title="[LinkedIn - new window]" href="https://www.linkedin.com/in/mikefoskett">Mike Foskett</a> &nbsp; <a class=myStuff_lnk target=popularpens title="[new window]" href="https://codepen.io/2kool2/pens/popular/?grid_type=list#">Popular pens</a> &nbsp; <a class=myStuff_lnk target=latestpens title="[new window]" href="https://codepen.io/2kool2/pens/public/?grid_type=list#">Latest pens</a> &nbsp; <a class=myStuff_lnk target=webSemantics title="[new window]" href="https://websemantics.uk/">webSemantics</a></footer>
            
          
!
            
              body {
  --spacing: .75rem;
  font-family: sans-serif;
  line-height: 1.5;
  text-align: center;
  margin: .75rem;
  padding-bottom: 2rem;
  color: hsl(269,19%,30%);
  background-color: hsla(32,100%,85%,.35);
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg width='100%25' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cfilter id='a'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.4'/%3E%3C/filter%3E%3C/defs%3E%3C!-- %3Cpath filter='url(%23a)' opacity='.3' d='M0 0h1200v256H0z'/%3E--%3E%3Crect filter='url(%23a)' opacity='.3' width='100%25' height='100%25'/%3E%3C/svg%3E");
}
@media (min-width: 48em) {
  body {--spacing: 1rem;}
}
body * {box-sizing: border-box;}
h1, h2, h3 {font-weight:100;}
h1 {margin: 1em 0 .5em;}
.group {
  border: 1px solid #fff;
  background-color: rgba(255,255,255,.25);
  padding: .5rem 1rem;
  margin: 1rem auto;
}

.url {
  display: flex;
  width: 100%;
  margin: 1rem auto;
}
[class*="_label"] {
  position: relative;
  white-space: nowrap;
  margin-right: .5em;
  min-width: 4em;
}
[class*="_label"] > span {
  display: block;
  position: relative;
  top: 50%;
  transform: translatey(-50%);
}
[class*="_input"] {
  display: inline-block;
  line-height: 1;
  width: 100%;
  margin: 0;
  padding: .25rem .5rem;
  font: inherit;
  border: 1px solid #fff;
  background-color: rgba(255,255,255,.5);
}


.upload {
  display: flex;
  width: 100%;
  margin: 1rem auto;
}

.player_audio {
  width: 100%;
}
.player_display {
  font-size: 1.25rem;
}
.tempo {
  display: flex;
  width: 100%;
  margin: 1rem auto;
}
.tempo_display {
  font-weight: 700;
  min-width: 3em;
  margin-left: .5em;
}
            
          
!
            
              
const player = document.querySelector('.player_audio');
const playerDisplay = document.querySelector('.player_display');

const changeTempo = function () {
  player.playbackRate = tempoInput.value;
  tempoDisplay.textContent = tempoInput.value;
};

const changeSongURL = function (e) {
  player.src = urlInput.value;
  let filename = player.src.split('\\').pop().split('/').pop();
  playerDisplay.textContent = filename;
}

const changeSongFile = function (e) {
  const target = e.currentTarget;
  const file = target.files[0];
  let reader;

  if (target.files && file) {
    reader = new FileReader();
    reader.onload = function (e) {
      player.setAttribute('src', e.target.result);
      playerDisplay.textContent = file.name;
      // player.play(); // auto play on load
    }
    reader.readAsDataURL(file);
  }
};

// Get the song from:
const urlInput = document.getElementById('url_input');
urlInput.addEventListener("change", changeSongURL, false);


// Or upload an MP3:
const uploadInput = document.getElementById('upload_input');
uploadInput.addEventListener('change', changeSongFile, false);


// Playback tempo 
const tempoInput = document.getElementById('tempo_input');
tempoInput.addEventListener("change", changeTempo, false);
const tempoDisplay = document.querySelector('.tempo_display');
tempoDisplay.textContent = tempoInput.value;



// Chords from:
const vtt = document.getElementById('url_input').value.replace('.mp3', '.vtt');
const player_chords = document.getElementById('player-chords');

player_chords.src = vtt;
// player.src = urlInput.value;
changeSongURL();
changeTempo();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console