0

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)

Tynvizz
  • 1
  • 1
  • Play the first one, they play another and so forth? – bipll Jan 22 '18 at 14:48
  • Presumably you can just `play` the stacking of them instead of writing it to disk: https://cournape.github.io/audiolab/fullapi.html#sound-output – Bailey Parker Jan 22 '18 at 14:48
  • @bipll Yea. That's the way I need to follow. Do You have any suggestions for some library? – Tynvizz Jan 23 '18 at 09:31
  • @BaileyParker, thanks. But Audiolab needs a lot of additional libraries. Is there something similar to Audiolab? – Tynvizz Jan 23 '18 at 09:33
  • In Multimedia section of Pydoc `wave` is chapter 21.5, and chapter 21.10 is `ossaudiodev`, I suggest you look at that. – bipll Jan 23 '18 at 09:35

0 Answers0