Hear Magic Clean models
The second cleaning stage behind Magic Clean, the tool that tidies up speech recordings for UK talking newspapers on Hear. It takes a recording of someone reading and removes coughs, sneezes, barks, door slams and background noise while keeping the reader's voice.
The model is MossFormer2 (48 kHz speech enhancement) fine-tuned on real Hear recordings. It runs after DeepFilterNet3 in the Hear cleaner, not in place of it. DeepFilterNet3's output is kept as a safety net and is put back wherever this model removes soft speech.
| Part | File | Size | Job |
|---|---|---|---|
| Model | second-stage/mossformer2-hear-d.ts.pt |
225 MB | For each 4-second window, decides how much of every frequency to keep |
| Tone target | second-stage/tone-target.npy |
4 KB | The average spectrum of clean Hear recordings, used by the tone step |
| Settings | second-stage/settings.json |
2 KB | Every number the recipe below needs |
| Portable weights | weights/mossformer2-hear-d.safetensors |
221 MB | The same weights as a plain state dict, for retraining or re-export |
| Reference code | reference/ |
15 KB | A small, complete implementation of the three steps |
Contents
- Repository layout
- Loading the model
- How the cleaner uses these files
- Training
- Results
- Limits
- Licences and credits
- Versions
Repository layout
manifest.json version, size and SHA-256 of every file
second-stage/
mossformer2-hear-d.ts.pt the model, ready to load with torch.jit.load
tone-target.npy 1,025 values, one per frequency bin of a 2,048-point FFT at 48 kHz
settings.json window sizes, mask settings, guard thresholds, tone limit
weights/
mossformer2-hear-d.safetensors 929 tensors, 55.3 million parameters
reference/
second_stage.py model stage: features, windows, mask shaping
guard.py speech guard
tone.py tone step, as NumPy and as an FFmpeg filter
A build only needs the second-stage/ folder. The weights/ and reference/ folders are for people working on the model.
Loading the model
Requirements: Linux, an NVIDIA GPU as device 0, PyTorch 2.8 with CUDA 12 and torchaudio 2.8. The model file was exported with torch 2.8.0+cu128 and runs on the GPU only.
import torch
from huggingface_hub import hf_hub_download
path = hf_hub_download(
"samuelr3/hear-magic-clean",
"second-stage/mossformer2-hear-d.ts.pt",
revision="v1",
)
model = torch.jit.load(path).eval()
with torch.inference_mode(), torch.jit.optimized_execution(False):
mask = model(features)
- Do not pass
map_location. The file stores its weights oncuda:0and a few shape constants on the CPU, and moving either breaks it. - Call it inside
torch.jit.optimized_execution(False). Otherwise PyTorch recompiles the model for 10 to 15 seconds the second time it meets each new batch size. Steady speed is within 10% either way. - Input: features,
float32, shape(batch, 496, 180), oncuda:0. That is one 4-second window per row. - Output: a mask,
float32, shape(batch, 496, 961). Multiply it into the window's spectrogram. - Batch size is free. 16 windows peak at about 0.7 GB of GPU memory.
To clean a file with the reference code:
python reference/second_stage.py second-stage/mossformer2-hear-d.ts.pt input.wav cleaned.wav
The input must be a 48 kHz WAV. Each channel is cleaned separately.
In a Docker build
The repository is public, so a build needs no token or login. Pin the revision and download only the build folder:
RUN huggingface-cli download samuelr3/hear-magic-clean \
--revision v1 --include "second-stage/*" "manifest.json" \
--local-dir /models/magic-clean/hear-magic-clean
Every file also has a plain URL, for builds without the Hugging Face client:
https://huggingface.co/samuelr3/hear-magic-clean/resolve/v1/second-stage/mossformer2-hear-d.ts.pt
https://huggingface.co/samuelr3/hear-magic-clean/resolve/v1/second-stage/tone-target.npy
https://huggingface.co/samuelr3/hear-magic-clean/resolve/v1/second-stage/settings.json
Then check every file against manifest.json before the image is used:
import hashlib, json, pathlib
root = pathlib.Path("/models/magic-clean/hear-magic-clean")
for item in json.loads((root / "manifest.json").read_text())["files"]:
path = root / item["path"]
if path.exists():
assert path.stat().st_size == item["bytes"], item["path"]
assert hashlib.sha256(path.read_bytes()).hexdigest() == item["sha256"], item["path"]
How the cleaner uses these files
The recording is decoded to 48 kHz and cleaned by DeepFilterNet3 first. Three steps follow. All the numbers are in second-stage/settings.json.
1. Model stage
- Cut each channel into 4-second windows that start every 3 seconds.
- Scale each window to a standard loudness (about -25 dB), and remember the scale.
- Compute the features: a 60-band Kaldi filter bank (40 ms window, 8 ms step) with its first and second differences, 180 values per frame. Add the dither to each frame first: random noise one 16-bit step in size. The model was trained with it, and leaving it out changes the result by 6 to 28 dB on real recordings.
- Run the model to get the mask, and shape it:
- Raise the mask to the power 2 where it is below 1. This deepens the noise removal.
- Where the speech in a window stops below about 9 kHz, relax the power to 0.5 above 3 to 5 kHz while speech is present. Without this, the top of the voice in narrow-band recordings is lost.
- If the profile sets an attenuation limit, never go below it.
- Multiply the mask into the window's spectrogram, turn it back into sound, undo the loudness scale, and keep the middle 3 seconds of each window.
2. Speech guard
The model sometimes removes soft word endings, such as a final "s". DeepFilterNet3 keeps them. The guard looks at short frames (10 ms steps) of the original, the DeepFilterNet3 output and the model output, and cross-fades the DeepFilterNet3 audio back in where all of these hold:
- the frame is within 0.2 s before or 0.8 s after speech;
- DeepFilterNet3 kept the sound (within 6 dB of the original);
- the model removed it (more than 8 dB below DeepFilterNet3);
- it is quiet compared with normal speech (its quarter-second average is at least 5 dB below the median speech level).
The last rule matters: a cough is as loud as speech, so it is never restored.
The guard also leaves long loud stretches with no speech alone. If the model removes at least 20 dB from a loud passage for 3 seconds or more, that passage is taken from DeepFilterNet3. This keeps jingles and music from being deleted.
On the test sets the guard restores between 0.1% and 1% of the audio.
3. Tone step
The cleaned recording's average spectrum is compared with tone-target.npy and nudged towards it by at most 3 dB per band, up to 14 kHz or the recording's own bandwidth. reference/tone.py shows the correction in NumPy and as one FFmpeg firequalizer filter. The Hear cleaner applies the same curve as a 2,049-tap filter with no delay, on the GPU.
Training
Starting point: the released MossFormer2_SE_48K weights from ClearerVoice-Studio.
Data:
| Kind | Source | Amount |
|---|---|---|
| Clean speech, real | Hear talking-newspaper recordings that passed a strict cleanliness check | 1,593 recordings from about 160 publications, cut into 29,108 four-second clips |
| Noisy speech, real | Hear recordings that failed the check | 17,964 four-second clips, 14,000 used |
| Noise, real | Pauses cut from noisy Hear recordings | 1,049 noise beds |
| Clean speech, studio | VCTK 0.92 and LibriTTS-R | 6,000 clips, passed through MP3 coding |
| Sudden noises | FSD50K clips and VocalSound coughs, sneezes and throat clears | 19,263 clips |
| Steady noise | DEMAND and FSD50K ambient clips | About 6 GB of 48 kHz audio |
About 475 hours of Hear recordings from 226 publications were scored to make this selection. Recordings with digitally silent pauses were left out, so the model is not taught to produce dead silence. Sixty publications were kept out of training entirely and used for testing.
Passes:
- First pass. 52,309 pairs: real clean clips with noise added (32,309), real noisy clips paired with the output of a mildly fine-tuned DeepFilterNet3 as the target (14,000), and studio clips (6,000). Learning rate 2e-5, batch 4, 13,078 steps.
- Second pass. Started from step 12,000 of the first. The same pairs, with 60% of the real clean targets replaced by that DeepFilterNet3's output on the same clip. Learning rate 1.5e-5, 13,078 steps. The checkpoint at step 12,000 scored best on a validation set of 60 held-out recordings and is the model published here.
The training target is the phase-sensitive mask, and the noisy input and its clean target are scaled by the same gain.
Results
"Chain" means all three steps above. "DeepFilterNet3" means the stock model at full strength. DNSMOS and NISQA are automatic listening scores from 1 to 5 that need no clean reference. PESQ compares against a clean reference.
| Test | Measure | Input | DeepFilterNet3 | Chain |
|---|---|---|---|---|
| Ten difficult recordings (28 minutes, 96 kbps MP3) | DNSMOS overall | 2.53 | 3.04 | 3.14 |
| NISQA | 2.36 | 3.02 | 3.56 | |
| Sixty recordings from publications held out of training | DNSMOS overall | 3.11 | 3.25 | 3.30 |
| NISQA | 3.46 | 3.78 | 4.08 | |
| Eight clips with a cough, sneeze, throat clear or bark | PESQ | 1.90 | 2.78 | 3.61 |
On the sixty held-out recordings the chain scored higher than DeepFilterNet3 on 46 and lower on 6 (NISQA).
In the Hear cleaner (Studio Voice profile, delivered MP3) the ten difficult recordings score DNSMOS 3.17 and NISQA 3.55 with this stage, and 3.07 and 3.13 without it. Whisper hears 7.7% of the original's words differently with the stage and 7.8% without.
Model stage alone, on studio speech with noise mixed in:
| Test | DeepFilterNet3 | Model stage |
|---|---|---|
| Clean speech, PESQ | 4.51 | 4.62 |
| Quiet clean speech, PESQ | 3.89 | 4.47 |
| Speech with sudden noises, PESQ | 2.81 | 3.20 |
| Sudden noises with no speech, dB removed | 20.4 | 38.1 |
Speed: in the Hear cleaner all three steps take about 25 seconds for 60 minutes of mono audio on an RTX A40, and 55 seconds for stereo. GPU memory peaks at 0.7 GB with 16 windows per batch.
Limits
- Soft speech. On clean recordings the chain turns quiet parts of speech down by 2.7 dB, against 0.9 dB for DeepFilterNet3. Do not run the model without the guard.
- Needs DeepFilterNet3. The guard uses its output and the original recording.
- No repair. It does not rebuild missing high frequencies or fix clipping, so heavily damaged recordings still sound damaged.
- Music and jingles. The model treats them as noise. Only the guard's long-passage rule protects them.
- Material. Trained and tested on English read speech. Other languages, singing and conversation with overlapping speakers are untested.
- GPU only. The model file is tied to PyTorch 2.8 with CUDA. For another version, rebuild it from the portable weights with the ClearerVoice-Studio model code.
- Repeatability. The dither is random, so two runs differ a little: by 40 to 55 dB below the signal on most recordings, and by a few dB inside passages the model is already removing. Seed the dither if you need the same output every time. The Hear cleaner does.
- Automatic scores. The scores above did not catch two faults that listening did (clipped word endings, and coughs restored by an earlier guard). Listen before changing any setting.
Licences and credits
This repository mixes licences. Check them before passing the weights on.
| Part | Source | Licence |
|---|---|---|
| Base model and architecture | MossFormer2_SE_48K, ClearerVoice-Studio | Apache-2.0 |
| Studio speech | VCTK 0.92, LibriTTS-R | CC BY 4.0 |
| Sudden and steady noises | FSD50K, clips under CC0 or CC BY only | CC0, CC BY |
| Coughs, sneezes, throat clears | VocalSound | CC BY-SA 4.0 |
| Steady noise | DEMAND | CC BY-SA 3.0 |
| Real speech and noise | Hear talking-newspaper recordings | Not public; used with Hear's permission |
| Teacher for the noisy clips | DeepFilterNet3, fine-tuned | MIT or Apache-2.0 |
The fine-tuned weights, the tone target and the reference code belong to Hear.
Versions
| Version | Date | Contents |
|---|---|---|
| v1 | 2026-11-15 | Second-pass model, guard with the cough and long-passage rules, tone limit 3 dB |
The files under second-stage/ have not changed since v1. Later commits on main only update this page and the reference code.
Model tree for samuelr3/hear-magic-clean
Base model
alibabasglab/MossFormer2_SE_48K