(audio, in_format)
| 85 | |
| 86 | |
| 87 | def decode_input_to_float(audio, in_format): |
| 88 | if in_format == "float32": |
| 89 | x = audio.astype(np.float32) |
| 90 | peak = np.max(np.abs(x)) |
| 91 | return x / peak if peak > 1.0 else x |
| 92 | |
| 93 | if in_format == "int16": |
| 94 | return np.clip(audio / 32768.0, -1.0, 1.0).astype(np.float32) |
| 95 | |
| 96 | if in_format == "uint8": |
| 97 | return np.clip((audio - 128.0) / 127.5, -1.0, 1.0).astype(np.float32) |
| 98 | |
| 99 | if in_format == "int24": |
| 100 | return np.clip(audio / 8388608.0, -1.0, 1.0).astype(np.float32) |
| 101 | |
| 102 | if in_format == "int32": |
| 103 | return np.clip(audio / 2147483648.0, -1.0, 1.0).astype(np.float32) |
| 104 | |
| 105 | raise ValueError(f"Unsupported input format {in_format}") |
| 106 | |
| 107 | |
| 108 | def remove_dc(audio): |
no test coverage detected