Here's one way to do it: the capacitor values are a guess. if the fan came with a speed controller use the capacitors it came with.
Capacitors should be mains capacitors, X1 rated or better.
the relays are solid-state relays.

simulate this circuit – Schematic created using CircuitLab
R1 R2 R3 R4 form a potential divider making sample voltages at 1.25 2.5 and 3.75v
The three comparators each compare a sample voltage against the input signal.
when the input it higher than the sample voltage to the corresponding comparator output goes to a low voltage allowing current to flow in the solid-state relay's input circuit.
So with 4V on the input all three relays are on and the fan motor sees full mains power voltage.
With 3V on the input the top relay SSR3 is off and so power to the motor has to flow through C2 this reduces the current available to the fan motor slowing it.
With 2V SSR2 and SSR3 are off and current has to flow through both C1 and C2 in series, this further reduces the current available and you get an even slower speed
With 1V the all three comparators are not conducting on their outputs so all three relays are off and thus there is no current to the motor