(x, dither=False, rng=None)
| 119 | |
| 120 | |
| 121 | def 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 | |
| 134 | def write_wav(audio_float, sample_rate, output_path, dither=False): |