Analyzes .wav file structure, reports any inconsistencies.
# ======================================
# .WAV file structure integrity test
# Alex Radzishevsky
# www.radzishevsky.com
# February 2026
# ======================================
import struct
import os
import sys
def get_audio_format(code):
formats = {
0x0001: "PCM (Integer)",
0x0003: "IEEE Float",
0x0006: "ALAW",
0x0007: "MULAW",
0xFFFE: "WAVE_FORMAT_EXTENSIBLE"
}
return formats.get(code, f"Unknown/Compressed (0x{code:04x})")
def hex_dump(data, length=64):
res = []
for i in range(0, min(len(data), length), 16):
chunk = data[i:i+16]
hex_str = " ".join(f"{b:02x}" for b in chunk)
ascii_str = "".join(chr(b) if 32 <= b <= 126 else "." for b in chunk)
res.append(f" {i:04x}: {hex_str:<48} |{ascii_str}|")
return "\n".join(res)
def inspect_wav_comprehensive(file_path):
if not os.path.exists(file_path):
print(f"Error: File '{file_path}' not found.")
return
file_size = os.path.getsize(file_path)
print(f"\n{'='*85}")
print(f" ANALYSIS REPORT: {os.path.basename(file_path)}")
print(f" SYSTEM FILE SIZE: {file_size} bytes")
print(f"{'='*85}\n")
with open(file_path, 'rb') as f:
# --- 1. INITIAL HEX DUMP ---
print("[01] HEADER HEX PREVIEW (First 64 Bytes)")
print(hex_dump(f.read(64)))
f.seek(0)
print("-" * 85)
# --- 2. GLOBAL RIFF HEADER ---
header = f.read(12)
if len(header) < 12:
print("[CRITICAL ERROR] File is smaller than a 12-byte RIFF header. Investigation aborted.")
return
tag, r_size, w_tag = struct.unpack('<4sI4s', header)
expected_riff_end = 8 + r_size
print(f"[02] GLOBAL CONTAINER")
print(f" Container ID: {tag.decode(errors='ignore')} (Expected: RIFF)")
print(f" Declared Size: {r_size} bytes")
print(f" Format Type: {w_tag.decode(errors='ignore')} (Expected: WAVE)")
if r_size != file_size - 8:
diff = (file_size - 8) - r_size
status = "TRAILING DATA" if diff 0 else "TRUNCATED"
print(f" !! … >>> Read the rest




