Previous Up Next

26.2.15  Joining audio clips together

The splice command joins two audio clips together with an overlap and optionally a crossfade.

Example

We load an audio file containing a speech2 and normalize it.

clip:=normalize(readwav("/home/luka/Downloads/gettysburg.wav"),-1)
     
a sound clip with 387574 samples at 22050 Hz (16 bit, mono)           

We want to remove the portion of the speech between 5.6 and 10.5 seconds. In order to do so, we splice the portions on the left and right, using an overlap of size 0.25 seconds. We plot the audio and mark the portion with a yellow rectangle.

t1:=5.6:; t2:=10.5:; cfl:=0.25:;
rectangle(t1-i,t2-i,t2+i,display=yellow+filled); plotwav(clip);

Now we extract audio from 0 to t1 and from t2 to the end and splice the resulting clips with an automatic crossfade. First we need to convert t1 and t2 to sample offsets.

sr:=samplerate(clip):; n:=round(sr*t1):; m:=round(sr*t2):; snd:=splice(clip(0,n),clip(m),cfl)
     
a sound clip with 274016 samples at 22050 Hz (16 bit, mono)           

Previous Up Next