Advertisement
here2share

# mp3_stereo.py

Feb 11th, 2021
1,152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. # mp3_stereo.py
  2.  
  3. from struct import pack
  4. from math import sin, pi
  5. import wave
  6. import random
  7.  
  8. RATE=44100
  9.  
  10. ## GENERATE STEREO FILE ##
  11. wv = wave.open('C://py//audio//test_stereo.mp3', 'w') # .mp3 or .wav
  12. wv.setparams((2, 2, RATE, 0, 'NONE', 'compressed'))
  13. maxVol=2**15-1.0 #maximum amplitude
  14. wvData=""
  15. for i in range(0, RATE*3):
  16.     wvData+=pack('h', maxVol*sin(i*500.0/RATE)) #500Hz left
  17.     wvData+=pack('h', maxVol*sin(i*200.0/RATE)) #200Hz right
  18. wv.writeframes(wvData)
  19. wv.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement