It's possible to do it in any language, but it's not that simple :-(, you'll need to decode the audio and store it neatly within a vector or array, the logical process is:
Decoding the first .mp3 file
store the decoded audio in a vector of N positions
Decode the next .mp3 file
Concatenate the new decoded vector at the end of the other vector
Do this and loop until you finish reading all of your .txt files
Encode vector to .mp3
Decoding .mp3 is quite complex, if you insist on using C I recommend you link your project with a specific lib able to decode, I've already used the #
In Python2.7 it can be relatively simple to decode .mp3 using Pymedia
import pymedia.audio.acodec as acodec
import pymedia.muxer as muxer
name='Sia - Chandelier.mp3';
name1= str.split(name,'.')
if name1[ -1 ].lower() == 'mp3':
dm= muxer.Demuxer( name1[ -1 ].lower() )
f=open(name, 'rb' )
dec= None
s= " "
sinal=[]
while len( s ):
s= f.read( 4096 )
if len( s ):
frames= dm.parse( s )
for fr in frames:
if dec== None:
dec= acodec.Decoder( dm.streams[ 0 ] )
r= dec.decode( fr[ 1 ] )
if r and r.data:
din = np.fromstring(r.data, dtype=np.int16)
sinal.append(din)
.mp3, you need something like this to do the encode:
# Open muxer and encoder
if enc== None:
params= { 'id': acodec.getCodecID(type),
'bitrate': bitrate,
'sample_rate': r.sample_rate,
'channels': r.channels }
print 'Encoder params:', params
mx= muxer.Muxer( type )
stId= mx.addStream( muxer.CODEC_TYPE_AUDIO, params )
enc= acodec.Encoder( params )
fw= open(fOutput, 'wb')
ss= mx.start()
fw.write(ss)
enc_frames= enc.encode( pack("%dh"%len(sinal), *(sinal)) )
if enc_frames:
for efr in enc_frames:
ss= mx.write( stId, efr )
if ss:
fw.write(ss)
If it were entirely in .wav this could be done in a few lines using python, hopefully this will give you a north!