lib/music/audio.py)
Scientific-pitch note names (A4 = 440 Hz), sine-wave melodies, playback,
and WAV/MP3 export. Load with
use music.audio;
(nested path) or
use music;
(folder package).
use music.audio;
audio.instrument("piano");
list.createList([A4, B4, C4, E5], melody);
melody.rhythm([1.0, 1.0, 0.5, 2.0]);
audio.play(melody);
print.number(music.frequency(A4));
audio.export(melody, "mp3");
audio.export(melody, "wav");
audio.instrument("piano")
before the melody — also
organ,
flute,
guitar,
violin,
bell,
square,
bass.
No argument returns the current name.
audio.instruments()
lists them.
C0…B8
are frequencies. Sharps/flats:
Cs4,
Db4,
REST (silence).
music.frequency(A4) or
music.frequency("C#4")
— Hz. A number is returned as-is.
melody.rhythm([1.0, 0.5, 2.0, …])
— beat lengths for whatever you named the note list (1 = one beat at the current BPM). One value per note. Also
audio.rhythm(melody, beats).
audio.play(melody [, bpm])
— default 120 BPM, one beat per note unless
rhythm was set. Needs pygame or
afplay /
aplay /
ffplay.
audio.export(melody, "mp3")
/
"wav"
— writes melody.mp3 or
melody.wav (cwd-relative).
Optional third argument: path string or BPM number.
pip install lameenc
(pip install 'someProgrammingLanguage[music]')
or ffmpeg on PATH.
Check audio.mp3Ok().
Example:
examples/music/melody.spl
(export) and
examples/music/play_melody.spl
(playback).
Implementation:
lib/music/audio.py +
someProgrammingLanguage/spl_music.py