generate_noise.py 941 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import struct
  2. import numpy as np
  3. import random
  4. from scipy import signal as sg
  5. f = 440 ## Frequency (in Hz)
  6. samplerate = 44100 ## Number of samples
  7. x = np.arange(630840)/float(samplerate)
  8. ####### sine wave ###########
  9. #y = np.int16(np.random.uniform(-20000,20000,630840) )
  10. y = np.int16(np.random.randint(-20000,20000,630840) )
  11. ####### square wave ##########
  12. # y = 100* sg.square(2 *np.pi * f *x / Fs )
  13. ####### square wave with Duty Cycle ##########
  14. # y = 100* sg.square(2 *np.pi * f *x / Fs , duty = 0.8)
  15. ####### Sawtooth wave ########
  16. # y = 100* sg.sawtooth(2 *np.pi * f *x / Fs )
  17. import numpy as np
  18. from scipy.io.wavfile import write
  19. write('test.wav', samplerate, y)
  20. '''
  21. ###### in jupyter, play generated audio #####
  22. import numpy
  23. import random
  24. from IPython.display import Audio
  25. print(random.randint(1,300))
  26. Audio(numpy.sin(numpy.linspace(0, 3000, 20000)*random.randint(1,300)), rate=8000)
  27. '''