Creating Karaoke of Music/Sound Using MATLAB

We all are familiar with Karaoke. And if you own a computer system, in past at-least once you might have tried to create a Karaoke from it. You might have googled software for it. Some of which you have found, are open-source and some, shareware with limitations.

But if you are a MATLAB coder why you want to do it all. Simply, do it MATLAB.

Just a few concepts you need to know for creating Karaoke from normal music file and you are all set to code.

For your information, There is no way to 100% remove the vocals from a song (Until and unless you are a DSP Engineer with passion to work with eerie details of finding the vocal frequencies and cutting them off). Accompaniment tracks are made in the studio, and our often referred to as minus one tracks because they are missing one track (in this case, the vocal track). The only way you would be able to remove the vocal track from the song entirely is if you have a multitrack version of the song, which is unlikely.

I am going to tell you a similar method:

Here I have used a stereo Wave file (.wav) to extract the instrument sound, separating it from the audio.

Following MATLAB code does the same.

[file, path] = uigetfile('*.wav','Select a .wav file');
if file == 0

out_dir = uigetdir(cd,'Choose output folder');
if out_dir == 0

[y,Fs,nbits]= wavread(file);

if size(y,2) == 1
    msgbox('The selected file is Mono. This algorithm is applicable only for Stereo files.');

fc=input('Enter Cutoff Frequency (HPF):');
if fc > 20
    fp = fc+5;
    fs = fc/(Fs/2);
    fp = fp/(Fs/2);
    [n wn] = buttord(fp,fs,0.5,80);
    [b, a] = butter(5,wn,'High');
    channel_2 = filtfilt(b,a,y(:,2));
    channel_2 = y(:,2);

karaoke_wav = y(:,1) - channel_2;

%Write it to a file
[p name ext] = fileparts(file);

if isdir(out_dir)
    wavwrite(karaoke_wav,Fs,nbits,[out_dir '\' name ext]);
    wavwrite(karaoke_wav,Fs,nbits,[cd '\' name ext]);

%Apply and Enjoy.

This code will first convert your stereo sound (.wav) file to mono file. Then try to apply a High Pass Filter on the resultant file.