MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / float_to_int16

Function float_to_int16

examples/csv2wav/csv2wav.py:121–131  ·  view source on GitHub ↗
(x, dither=False, rng=None)

Source from the content-addressed store, hash-verified

119
120
121def float_to_int16(x, dither=False, rng=None):
122 y = np.clip(x, -1.0, 1.0) * 32767.0
123 if dither:
124 if rng is None:
125 rng = np.random.default_rng()
126 tpdf = rng.random(y.shape, dtype=np.float32) - rng.random(
127 y.shape, dtype=np.float32
128 )
129 y = y + tpdf
130
131 return np.round(y).astype(np.int16)
132
133
134def write_wav(audio_float, sample_rate, output_path, dither=False):

Callers 1

write_wavFunction · 0.85

Calls 2

clipMethod · 0.80
roundMethod · 0.80

Tested by

no test coverage detected