I've got Python script for merge .wav files, based on list with paths.
It's based on this code
import wave
infiles = ["sound_1.wav", "sound_2.wav"]
outfile = "sounds.wav"
data= []
for infile in infiles:
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()
from this topic How to join two wav files using python? But I realized, It takes too much time to generate file. In fact I don't need to store merged data as the file on physical disk.
So question is, is there any way to read .wav files merge them and play it just from RAM memory?
EDIT: I forgot to specify, that I need to play it using Raspberry pi 3. I tried to use PyAudio which on my laptop works fine, but when I tried it in RPI the sound is slowly and crackling (I used this example https://people.csail.mit.edu/hubert/pyaudio/docs/#example-blocking-mode-audio-i-o)