You use the analogWrite function. If you are writing to a DAC pin (A21/A22 on the Teensy 3.5/3.6, A14 on the Teensy 3.1/3.2, or A12 on the Teensy LC), it does a real analog write (i.e. adjusts the voltage of the pin). You might need an amplifier on the pin(s) before connecting it to a speaker.
Due to poor naming of the function from original Arduino systems, analogWrite on a digital pin that supports PWM, rapidly turns the pin on/off, so that it approximates an analog signal (if you are looking at a LED, it will appear to dim the LED, as the light turns on/off faster than the eye can see). Typically you would need a low pass filter if you want a PWM output to better approximate an analog signal.
And yes, IMHO, the original Arduino should have called the second function something like pwmWrite, but they didn't.