{"record":{"id":"d7fe5d135d5139ad","repo":"CorentinJ/Real-Time-Voice-Cloning","slug":"unsupported-wave-file-format","errorCode":null,"errorMessage":"Unsupported wave file format","messagePattern":"Unsupported wave file format","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"utils/logmmse.py","lineNumber":232,"sourceCode":"#         \n#         vad[k:k + len2] = vad_decision >= eta\n#         \n#     vad = np.pad(vad, (0, len(wav) - len(vad)), mode=\"constant\")\n#     return vad\n\n\ndef to_float(_input):\n    if _input.dtype == np.float64:\n        return _input, _input.dtype\n    elif _input.dtype == np.float32:\n        return _input.astype(np.float64), _input.dtype\n    elif _input.dtype == np.uint8:\n        return (_input - 128) / 128., _input.dtype\n    elif _input.dtype == np.int16:\n        return _input / 32768., _input.dtype\n    elif _input.dtype == np.int32:\n        return _input / 2147483648., _input.dtype\n    raise ValueError('Unsupported wave file format')\n\n\ndef from_float(_input, dtype):\n    if dtype == np.float64:\n        return _input, np.float64\n    elif dtype == np.float32:\n        return _input.astype(np.float32)\n    elif dtype == np.uint8:\n        return ((_input * 128) + 128).astype(np.uint8)\n    elif dtype == np.int16:\n        return (_input * 32768).astype(np.int16)\n    elif dtype == np.int32:\n        print(_input)\n        return (_input * 2147483648).astype(np.int32)\n    raise ValueError('Unsupported wave file format')\n","sourceCodeStart":214,"sourceCodeEnd":248,"githubUrl":"https://github.com/CorentinJ/Real-Time-Voice-Cloning/blob/890f3a03187195b9829db2079b75c2ba2ab0405c/utils/logmmse.py#L214-L248","documentation":"First of the two 'Unsupported wave file format' ValueErrors in utils/logmmse.py, raised by to_float() when the input array's dtype is none of float64/float32/uint8/int16/int32. to_float normalizes PCM samples to float64 for log-MMSE denoising; any other dtype (int8, int24 stored wider, float16, complex) falls through all branches and is rejected. The accepted set mirrors the dtypes libsoundfile/scipy wave readers commonly produce.","triggerScenarios":"Calling logmmse/logmmse_from_file (utils/logmmse.py) with wav data loaded by a reader that yields an unsupported dtype — e.g. soundfile with dtype='float16' (not typical but possible), manually constructed int8 arrays, or a 24-bit PCM file read as raw bytes and reshaped.","commonSituations":"User-supplied recordings in exotic formats fed to the toolbox's noise reduction; preprocessing pipelines that pass pre-normalized or non-standard arrays; scipy.io.wavfile.read on 24-bit wavs (rare, returns int32 but some forks differ); arrays coming from another library's float16 pipeline.","solutions":["Convert before calling: wav.astype(np.float32) for floats, or np.int16 / np.int32 for PCM — to_float accepts those.","Load with a standard reader that returns int16/float32, e.g. librosa.load(..., sr=None) or soundfile.read(..., dtype='float32').","If you own the data, re-encode the source audio to 16-bit PCM wav."],"exampleFix":"# before\nwav, sr = load_some_reader(file)  # dtype == np.int8\nlogmmse(wav, sr)  # ValueError: Unsupported wave file format\n\n# after\nwav = wav.astype(np.float32) / 32768.0 if wav.dtype == np.int16 else wav.astype(np.float32)\nlogmmse(wav, sr)","handlingStrategy":"type-guard","validationCode":"import numpy as np\n\nSUPPORTED = (np.float64, np.float32, np.uint8, np.int16, np.int32)\n\ndef dtype_supported(arr: np.ndarray) -> bool:\n    return arr.dtype.type in SUPPORTED","typeGuard":"import numpy as np\n\ndef is_supported_pcm_dtype(a) -> bool:\n    return isinstance(a, np.ndarray) and a.dtype.type in (np.float64, np.float32, np.uint8, np.int16, np.int32)","tryCatchPattern":"try:\n    denoised = logmmse(wav, sr)\nexcept ValueError as e:\n    if \"Unsupported wave file format\" in str(e):\n        wav = wav.astype(np.int16 if wav.dtype.kind == 'i' else np.float32)\n        denoised = logmmse(wav, sr)\n    else:\n        raise","preventionTips":["Always load audio with a reader returning int16 or float32 (librosa, soundfile defaults).","Validate dtype at your pipeline's trust boundary, before denoising.","Standardize on 16-bit PCM wav for user-supplied recordings."],"tags":["audio","dtype","logmmse","noise-reduction"],"backgroundTag":null,"analyzedSha":"890f3a03187195b9829db2079b75c2ba2ab0405c","analyzedAt":"2026-08-15T02:15:13.202Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}