code: 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)
docs: Save a given signal ``sig`` to file ``fname`` as a 16-bit one-channel wave
    with the given ``rate`` sample rate.