Saturday, 9 December 2017

Speeding up / down audio files

My children want to have some of the songs they listen on the radio in their MP3s.

This is a no-brainer. After they find the videos they want in YouTube, I put all the URLs in a file ('bajar.txt') and can get all the MP3 files with the following command.

youtube-dl -a bajar.txt -x --audio-format mp3 -o '%(title)s.%(ext)s'

But the second step is a bit more fun. One of the MP3s is wrong and it plays the songs a bit slower than it should. Instead of buying a new one, I just speed up the MP3 files in the computer before uploading them to the player. This script will just get all the *mp3 files in a directory, speed them up according to the SP factor, and copy them to the directory 'emma_mp3s', ready to upload to my daughter's player (modifying the IFS variable allows having white spaces in the file names)

#!/bin/bash
# mp3speed.sh                                                                                                                                                          # Adapted from https://ubuntuforums.org/showthread.php?t=1259851                    
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

FILES="*.mp3"
mkdir -p emma_mp3s
for f in $FILES

do
 AR=96k
 SP=1.08897   # Speed up:  ini_length * (1/speedup) = final_length

 echo Encoding $f

 mplayer -af scaletempo -speed $SP $f -vc null -vo null -ao pcm:fast:waveheader:file=$f.wav

 ffmpeg -i $f.wav -acodec libmp3lame -ab $AR emma_mp3s/$f
 rm $f.wav

done

IFS=$SAVEIFS


4 comments:

ark bug repellent id said...

Thanks for the tip! I am watching all of your videos to learn how to work it properly, but here is the catch, I am making a mash-up of songs (the background music and vocals will be edited and moved around to fit into a new song). So I am wondering how to remove the music and keep the vocals and I will mess around with the tracks (for the multiple songs) to see how this works.



eu4 console commands said...

How do you speed up music while the rest is normal, like you import your music then it starts as normal but then later it goes faster/rapidly like how can you do it like that?


molasses benefits for hair said...

I put in an MP3 file, and I want to speed it up, however, none of the options in effects are available, except phaser. I want to speed it up 1000%. How can I fix this problem?

angelv said...

Hi "molasses benefits for hair",

no idea what software you are using when you say that only phaser is available. The script I wrote about here is meant to be run in Linux, and you will need mplayer and ffmpeg installed.

Cheers,