Skip to content

Instantly share code, notes, and snippets.

@richtier
Created May 10, 2017 22:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richtier/6b05b2bb3ceff20f3d9557227b8789c6 to your computer and use it in GitHub Desktop.
Save richtier/6b05b2bb3ceff20f3d9557227b8789c6 to your computer and use it in GitHub Desktop.
import array
import struct
def float_to_16_bit_pcm(raw_floats):
floats = array.array('f', raw_floats)
samples = [sample * 32767 for sample in floats]
raw_ints = struct.pack("<%dh" % len(samples), *samples)
return raw_ints
@ArpitPWellNest
Copy link

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment