(self, waveform, n_quantizers=N_QUANTIZERS)
| 102 | |
| 103 | class _Enc: |
| 104 | def encode(self, waveform, n_quantizers=N_QUANTIZERS): |
| 105 | if waveform.ndim == 1: |
| 106 | waveform = waveform[np.newaxis, np.newaxis, :] |
| 107 | elif waveform.ndim == 2: |
| 108 | waveform = waveform[np.newaxis, :] |
| 109 | T = waveform.shape[-1] |
| 110 | padded = ((T + DOWNSAMPLE_RATE - 1) // DOWNSAMPLE_RATE) * DOWNSAMPLE_RATE |
| 111 | if padded != T: |
| 112 | waveform = np.concatenate( |
| 113 | [waveform, np.zeros((1, 1, padded - T), dtype=np.float32)], axis=-1, |
| 114 | ) |
| 115 | waveform = waveform.astype(np.float32) |
| 116 | nq = np.array(n_quantizers, dtype=np.int64) |
| 117 | r = engine.run(outs, {ins[0]: waveform, ins[1]: nq}) |
| 118 | return r[0][:, 0, :int(r[1][0])].T.astype(np.int64) |
| 119 | |
| 120 | def close(self): |
| 121 | engine.close() |
no test coverage detected