How to Use FFmpeg Vocoder Filter

This article explains how to use the vocoder audio filter in FFmpeg to create classic robotic voice effects. You will learn how to prepare your modulator (voice) and carrier (synthesizer) signals, merge them into a single stereo stream, and apply the filter with customized parameters to control the output.

Understanding the Vocoder Inputs

The FFmpeg vocoder filter requires a single stereo input stream where:

  • Left Channel (Channel 0): The modulator (usually a voice recording or speech).
  • Right Channel (Channel 1): The carrier (usually a synthesizer chord, noise, or a rich harmonic instrument).

The filter uses the spectral envelope of the Left channel (voice) and applies it to the Right channel (synth) to create the synthesized speaking effect.

The Basic FFmpeg Command

To use the filter, you must first merge your separate voice and synthesizer audio files into a stereo track using the amerge filter, and then pass that combined stream into the vocoder filter.

Here is the standard command:

ffmpeg -i voice.wav -i synth.wav -filter_complex "[0:a][1:a]amerge=inputs=2[stereo];[stereo]vocoder[out]" -map "[out]" output.wav

Command Breakdown:

  • -i voice.wav: Input 0, your vocal track (modulator).
  • -i synth.wav: Input 1, your instrument track (carrier).
  • [0:a][1:a]amerge=inputs=2[stereo]: Combines the two mono inputs into a single stereo stream named [stereo]. Input 0 becomes the left channel and Input 1 becomes the right channel.
  • [stereo]vocoder[out]: Applies the vocoder filter to the merged stereo stream.
  • -map "[out]": Maps the processed audio output to the final file output.wav.

Customizing Vocoder Parameters

You can fine-tune the vocoder effect using specific parameters. The syntax is vocoder=parameter1=value1:parameter2=value2.

The available parameters are:

  • rd (Release/Decay time): Controls the response time of the envelope follower in seconds. The default is 0.02. Lower values make the effect more responsive; higher values make it smoother.
  • decay (Decay rate): Sets the decay factor for the filter bands. The default is 0.05.
  • points (Number of bands): The number of frequency bands used for the analysis. The default is 2000. Higher values provide more detailed frequency resolution but require more processing power.
  • gain (Output gain): Multiplies the output volume. The default is 1.0.

Example with Custom Parameters:

To increase the number of bands for a clearer voice and slightly increase the decay time, use the following command:

ffmpeg -i voice.wav -i synth.wav -filter_complex "[0:a][1:a]amerge=inputs=2[stereo];[stereo]vocoder=points=4000:rd=0.05:decay=0.1:gain=1.5[out]" -map "[out]" output_custom.wav