Advertisement
Guest User

huita3

a guest
Nov 5th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. from __future__ import print_function
  2. import sys
  3. import numpy as np
  4. import scipy.io.wavfile as io
  5. from scipy.special import _ufuncs_cxx
  6. from scipy.sparse.csgraph import _validation
  7.  
  8. Fs = 48000 #Hz
  9.  
  10. truel = 0.01 #S
  11. falsel = 0.005 #S
  12. interval = 0.001 #S
  13.  
  14. if len(sys.argv)==1:
  15.     print ('Usage: python huita.py inputfile.txt')
  16.     print ('or: python huita.py inputfile.txt 0.01 0.005 0.001, 48000')
  17.     print ('numbers: length of 1 in seconds, length of 0 is seconds, interval',
  18.            'in seconds, sampling rate in Hz')
  19.     print ('outputs output.wav')
  20.     raise IOError("No file provided")
  21. if len(sys.argv)==6:
  22.     truel =     float(sys.argv[2])
  23.     falsel =    float(sys.argv[3])
  24.     interval =  float(sys.argv[4])
  25.     Fs =        int(sys.argv[5])
  26.    
  27. with open(sys.argv[1], 'r') as f:
  28.     i = f.read()
  29.  
  30. s = []
  31. for nr, bit in enumerate(i):
  32.     s.append(np.zeros(interval*Fs))
  33.     if bit == '1':
  34.         s.append(np.ones(truel*Fs))
  35.     elif bit == '0':
  36.         s.append(np.ones(falsel*Fs))
  37. s.append(np.zeros(interval*Fs))
  38.  
  39. s = np.hstack(s)
  40.  
  41. io.write('output.wav', Fs, s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement