def save_to_16bit_wave_file ( fname , sig , rate ) : with closing ( wave . open ( fname , "wb" ) ) as wave_file : wave_file . setnchannels ( 1 ) wave_file . setsampwidth ( 2 ) wave_file . setframerate ( rate ) for chunk in chunks ( ( clip ( sig ) * 2 ** 15 ) . map ( int ) , dfmt = "h" , padval = 0 ) : wave_file . writeframes ( chunk )
add high frequency signal to wave file python
Save a given signal sig to file fname as a 16 - bit one - channel wave with the given rate sample rate .
def save_to_16bit_wave_file(fname, sig, rate):
  """
  Save a given signal ``sig`` to file ``fname`` as a 16-bit one-channel wave
  with the given ``rate`` sample rate.
  """
  with closing(wave.open(fname, "wb")) as wave_file:
    wave_file.setnchannels(1)
    wave_file.setsampwidth(2)
    wave_file.setframerate(rate)
    for chunk in chunks((clip(sig) * 2 ** 15).map(int), dfmt="h", padval=0):
      wave_file.writeframes(chunk)