Yesterday I needed to combine several audio files and I figured out to do this with command lines. It was not as easy as I expected but I guess I underestimated how little I know about audio files! Anyway, below I explain what I did!
Preparing my audio files
I had several audio files that I recorded with the voice
recorder
available on my phone. This application saves audio files as
.m4a
, so basically I had a
bunch of .m4a
files!
Between every file I recorded I needed to add a blank, so instead of recording a blank, I created blank of 30 seconds with FFmpeg (see this gist):
|
|
Then I had to so some cuts. For instance, I needed to only use the first 1min 30sec
part2_all.m4a
, so I used FFmpeg one more time:
|
|
and so I obtained part2c.m4a
. That being done I had all the files I needed.
Concatenate the files
That was the tricky part, cause it is not super easy to
concatenate audio files because of codecs and timestamps… As all my files where all in .m4a
I thought I woul be able to use the FFmpeg
to concatenate files with same
codecs, but it did not
work. I try to use other formats but it did not work either. Fortunately, I
stumbled into the following
answer
that gives valuable information about this. The solution proposed is to convert files to
Pulse-code modulation, then
use a simple file concatenation with cat
(cause this is possible with such files)
and then convert the file thereby obtained back to .m4a
. So this is what I have done:
|
|
and so I got final.m4a
💥!
Two last remarks. First, I have also tried with .aac
files following this answer
, but
it did not work. And again I can just blame myself for not knowing enough about
this, so I still do really know why… I guess it means that I can learn a
lot about audio files! Second, I would like to mention SoX that looks like a
very handy tool for this kind of manipulation, but I did not test it yet! Maybe next time!