-
Notifications
You must be signed in to change notification settings - Fork 1
/
merging_wavs.py
36 lines (32 loc) · 1.13 KB
/
merging_wavs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
##merging individual wavs
import os
import wave
import soundfile
path_to_dir = "out"
list_of_dirs = os.listdir(path_to_dir)
for dirs in list_of_dirs:
the_numbers_list = []
list_in_files = []
list_of_files = os.listdir(path_to_dir)
for wavs in list_of_files:
the_numbers = wavs.split(".wav")[0]
the_numbers_list.append(int(the_numbers))
the_numbers_list.sort(key=int)
for things in the_numbers_list:
list_in_files.append("out"+"/"+str(things)+".wav") ###test needs to be changed later into the real dir
infiles = list_in_files
for files in infiles:
#print(files)
data, samplerate = soundfile.read(files)
soundfile.write(files, data, samplerate, subtype="PCM_16")
outfile = ('out'+".wav")###test needs to be changed later into the real dir
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])
for i in range(len(data)):
output.writeframes(data[i][1])
output.close()