1

In my system i have to list all the wav files from one folder and then i have to bind that files as one file. I have the code to bind two files but i have 8 or more sound file i have to bind those file. Anybody can you help me? Stackoverflow solution have merge only two audio file. I have to merge lot of audio file from the folder. I don't know how many audio file will come into that folder.

this code is bind two files:

 print(glob.glob('upload/updated_audios/*.wav'))
    file_data = glob.glob('upload/convertedAudio/*.wav')
    outfile = "upload/output_files/output.wav"

    data = []
    for infile in file_data:
        w = wave.open(infile, 'rb')
        data.append([w.getparams(), w.readframes(w.getnframes())])
        w.close()

    output = wave.open(outfile, 'wb')
    output.setparams(data[0][0])
    output.writeframes(data[0][1])
    output.writeframes(data[1][1])
    output.close()

1 Answers1

1
file_data = glob.glob('upload/convertedAudio/*.wav')
outfile = "upload/output_files/output.wav"

    with wave.open(outfile, 'wb') as wav_out:
        for wav_path in file_data:
            with wave.open(wav_path, 'rb') as wav_in:
                if not wav_out.getnframes():
                    wav_out.setparams(wav_in.getparams())
                wav_out.writeframes(wav_in.readframes(wav_in.getnframes()))

this code is working but i can't merge orderly. this answer already in stackoverflow question. but that question is different so this answer is most suitable for this question.

note: order mean ascending and descending.