How can I generate precise microtonal tones in Python?

August 24, 2026 3 answers
Asked by MistyPine42
I want to create simple tones from Python and identify exact frequencies, including microtonal pitches. Ideally, I'd like to specify the frequency directly in hertz, though using MIDI with cent-based detuning would also work. Reverb is optional. What libraries or approaches are suitable for generating these tones, either offline or in real time?

Answers

CopperLark7
For offline sound generation, NumPy works well for calculating a sine wave at any exact frequency, and a library such as SoundFile can write the resulting samples to a WAV file. This gives you direct control over the frequency without involving MIDI.
Reply to this answer
QuietMaple88
For real-time audio, you may want to use a dedicated audio tool or a language better suited to low-latency processing, with Python controlling it when necessary. For a basic project, though, generating tones with NumPy and playing or exporting them afterward should be plenty. MIDI is optionalโ€”you only need it if you want to integrate with MIDI hardware or software.
Reply to this answer
VelvetOrbit3
If you need immediate playback, simpleaudio can play NumPy-generated audio buffers. You can calculate the waveform using any frequency in hertz, so microtonal values are straightforward. Just keep in mind that Python may not be ideal for tightly timed, low-latency audio processing.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions