Join multiple mp3 files into a single mp3 file [closed]

0

Hello! I would like to create a program (in C language or another capable) that receives as input a text and returns me as output a song.

For this I would need a text file (.txt) where I would need to read it and several audio files (.mp3) each with a musical note. Let the letter A represent the note Dó.mp3 the letter B present the note A.mp3 the sequence of the letters A and C the note Ré.mp3.

Reading the file for me would not be a problem my difficulty is to merge these .mp3 files according to the sequence of the text and transform them into a single .mp3 file.

I just do not know where to start. I've talked to some teachers but no one knows how. So I ask you:

How do I add multiple mp3 files to a single mp3 file? Can you point me to any path (websites, books,     

asked by anonymous 08.12.2016 / 21:05

1 answer

3

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!

        
    09.12.2016 / 23:54