Advertisement
yclee126

Combine sounds into one

Jan 17th, 2022
947
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. # combine all individual graph sounds into one waveform
  2.  
  3. import soundfile as sf
  4. import numpy as np
  5.  
  6. idle_time = 0.5
  7. graph_duration = 5.0
  8.  
  9. data, samplerate = sf.read('graphs_clean.wav')
  10. graph_samples = int(graph_duration*samplerate)
  11.  
  12. last_time = 0
  13. start_points = []
  14. for i, samp in enumerate(data):
  15.     cur_time = i / samplerate
  16.     if np.abs(samp[0]) > 0.001 or np.abs(samp[1]) > 0.001:
  17.         if cur_time - last_time > idle_time:
  18.             start_points.append(i)
  19.         last_time = cur_time
  20.  
  21. arr = np.zeros((graph_samples, 2))
  22.  
  23. for point in start_points:
  24.     arr += data[point:point+graph_samples]
  25. arr /= len(start_points)
  26.  
  27. sf.write('graph_combined.wav', arr, samplerate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement