Skip to main content
PreprocessOptions controls how Tafrigh preprocesses your audio before splitting and transcription. Proper preprocessing can dramatically improve transcription accuracy by reducing background noise, isolating voice frequencies, and enhancing speech clarity.

Why preprocessing matters

Audio preprocessing improves transcription accuracy by:
  • Reducing noise: Removes background hiss, hum, and environmental sounds
  • Isolating speech: Filters out frequencies outside the human voice range
  • Enhancing clarity: Boosts mid-range frequencies where speech is most prominent
  • Normalizing volume: Ensures consistent audio levels across the file

Configuration

You pass preprocessOptions to the transcribe() function:
import { transcribe } from 'tafrigh';

const transcript = await transcribe('audio.mp3', {
  preprocessOptions: {
    noiseReduction: {
      afftdnStart: 1,
      afftdnStop: 1,
      afftdn_nf: -25,
      dialogueEnhance: true,
      lowpass: 1,
      highpass: 200,
    },
  },
});

Properties

noiseReduction
object | null
Controls noise reduction and audio filtering. Set to null to skip preprocessing entirely.
All individual filter properties can be set to null to omit that specific filter while keeping others active.

Examples

Disable preprocessing completely

Skip all preprocessing when your audio is already clean:
const transcript = await transcribe('clean-audio.mp3', {
  preprocessOptions: {
    noiseReduction: null,
  },
});

Light noise reduction

For moderately clean recordings:
const transcript = await transcribe('podcast.mp3', {
  preprocessOptions: {
    noiseReduction: {
      highpass: 200,
      lowpass: 3500,
      afftdnStart: 0,
      afftdnStop: 0.5,
      afftdn_nf: -15,
      dialogueEnhance: true,
    },
  },
});

Aggressive noise reduction

For noisy environments or low-quality recordings:
const transcript = await transcribe('noisy-recording.mp3', {
  preprocessOptions: {
    noiseReduction: {
      highpass: 250,
      lowpass: 3000,
      afftdnStart: 0.5,
      afftdnStop: 2.5,
      afftdn_nf: -35,
      dialogueEnhance: true,
    },
  },
});

Male voice optimization

Optimized for lower-pitched male voices:
const transcript = await transcribe('male-speaker.mp3', {
  preprocessOptions: {
    noiseReduction: {
      highpass: 100,  // Lower to preserve male fundamentals
      lowpass: 3000,
      afftdnStart: 0,
      afftdnStop: 1,
      afftdn_nf: -20,
      dialogueEnhance: true,
    },
  },
});

Female voice optimization

Optimized for higher-pitched female voices:
const transcript = await transcribe('female-speaker.mp3', {
  preprocessOptions: {
    noiseReduction: {
      highpass: 200,  // Higher to remove more low-frequency noise
      lowpass: 4000,  // Higher to preserve more harmonics
      afftdnStart: 0,
      afftdnStop: 1,
      afftdn_nf: -20,
      dialogueEnhance: true,
    },
  },
});

Selective filtering

Use only specific filters by setting others to null:
const transcript = await transcribe('audio.mp3', {
  preprocessOptions: {
    noiseReduction: {
      highpass: 300,
      lowpass: null,           // Disable low-pass filter
      afftdnStart: null,       // Disable FFT denoising
      afftdnStop: null,
      afftdn_nf: null,
      dialogueEnhance: true,
    },
  },
});

Preprocessing callbacks

Monitor preprocessing progress with callbacks:
const transcript = await transcribe('audio.mp3', {
  preprocessOptions: {
    noiseReduction: {
      // ... your settings
    },
  },
  callbacks: {
    onPreprocessingStarted: async (filePath) => {
      console.log(`Starting preprocessing: ${filePath}`);
    },
    onPreprocessingProgress: async (percent) => {
      console.log(`Preprocessing: ${percent}% complete`);
    },
    onPreprocessingFinished: async (filePath) => {
      console.log(`Finished preprocessing: ${filePath}`);
    },
  },
});

Finding the right noise sample

For FFT-based denoising (afftdnStart, afftdnStop, afftdn_nf), you need a portion of your audio that contains only background noise:
  1. Listen to your audio and find a segment with no speech
  2. Note the timestamp where noise-only audio begins
  3. Set the duration to capture 0.5-3 seconds of noise
  4. Configure the parameters:
const transcript = await transcribe('audio.mp3', {
  preprocessOptions: {
    noiseReduction: {
      afftdnStart: 5.0,    // Noise sample starts at 5 seconds
      afftdnStop: 7.0,     // Noise sample ends at 7 seconds
      afftdn_nf: -25,      // Moderate noise reduction
      // ... other settings
    },
  },
});
If your audio has no clean noise-only segments, set afftdnStart, afftdnStop, and afftdn_nf to null and rely on the highpass/lowpass filters instead.

Understanding filter interactions

Preprocessing filters are applied in sequence:
  1. High-pass filter: Removes low frequencies (rumble, hum)
  2. Low-pass filter: Removes high frequencies (hiss, artifacts)
  3. FFT denoising: Learns and removes noise profile
  4. Dialogue enhancement: Boosts speech frequencies
  5. Normalization: Ensures consistent volume levels
Each filter builds on the previous one to progressively improve audio quality.
Over-aggressive filtering can remove important speech information. Start with default values and adjust incrementally based on transcription results.

Noise reduction

Deep dive into noise reduction options

Split options

Configure audio chunk splitting

Build docs developers (and LLMs) love