Advertisement
yclee126

beep sound writer

Aug 4th, 2021 (edited)
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. f = open('labels_processed.txt', 'r')
  2. y, sr = librosa.load('morse.wav', sr=None)
  3. sample_time = len(y)/sr
  4. # out = open('labels_excel.txt', 'w')
  5.  
  6. sound = np.zeros((len(y)), dtype='float')
  7. stat = True # init. condition
  8. prev_pos = 0
  9.  
  10. while True:
  11. line = f.readline()
  12. if not line:
  13. f.close()
  14. break
  15. pos = int(float(line.split('\t')[0]) / 10 * sr)
  16.  
  17. if stat:
  18. sound[prev_pos:pos] = librosa.tone(800, sr=44100, length=(pos - prev_pos))
  19. else:
  20. prev_pos = pos
  21. stat = not stat
  22.  
  23. sf.write('sound_inv.wav', sound, sr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement