Skip to content

Instantly share code, notes, and snippets.

@yogiblue
Last active January 5, 2016 12:32
Show Gist options
  • Save yogiblue/4f011ea67200f07b221f to your computer and use it in GitHub Desktop.
Save yogiblue/4f011ea67200f07b221f to your computer and use it in GitHub Desktop.
Split a directory of two channel wav recordings into separate mono flac files
function [ ] = SplitAudioChannels( )
%SPLITAUDIOCHANNELS Split a 2 channel wav file into two flac files
% Reads a directory of wav files containing 2 channels of audio
% Reads in the wav file, stores the left hand recording
% Repeats the process for the right hand recording
% All audio files start with the name 2014/2015
AllFiles = dir('201*.wav');
% Computes the number of files in the current directory
NumFiles = length(AllFiles);
display('Splitting audio channels');
display('Making left and right directories ');
mkdir('left');
mkdir('right');
display('Processing ... ');
display(num2str(NumFiles));
for i = 1:NumFiles
display(AllFiles(i).name)
C = strsplit(AllFiles(i).name, '.');
[y2,Fs2]=audioread(AllFiles(i).name);
y2(:,2)=[];
outfile = strcat('left\',C(1),'_l.flac');
audiowrite(outfile{1}, y2, Fs2)
clear y2;
[y2,Fs2]=audioread(AllFiles(i).name);
y2(:,1)=[];
outfile = strcat('right\',C(1),'_r.flac');
audiowrite(outfile{1}, y2, Fs2)
clear y2;
end
display('Finished');
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment