ptttl package

Submodules

ptttl.audio module

ptttl.audio.ptttl_to_mp3(ptttl_data, mp3_filename, amplitude=0.5, wavetype=0)

Convert a PTTTLData object to audio data and write it to an .mp3 file (requires the LAME audio mp3 encoder to be installed and in your system path).

Parameters
  • ptttl_data (str) – PTTTL/RTTTL source text

  • mp3_filename (str) – Filename for output .mp3 file

  • amplitude (float) – Output signal amplitude, between 0.0 and 1.0.

  • wavetype (int) – Waveform type for output signal. Must be one of tones.SINE_WAVE, tones.SQUARE_WAVE, tones.TRIANGLE_WAVE, or tones.SAWTOOTH_WAVE.

ptttl.audio.ptttl_to_samples(ptttl_data, amplitude=0.5, wavetype=0)

Convert a PTTTLData object to a list of audio samples.

Parameters
  • ptttl_data (PTTTLData) – PTTTL/RTTTL source text

  • amplitude (float) – Output signal amplitude, between 0.0 and 1.0.

  • wavetype (int) – Waveform type for output signal. Must be one of tones.SINE_WAVE, tones.SQUARE_WAVE, tones.TRIANGLE_WAVE, or tones.SAWTOOTH_WAVE.

Returns

list of audio samples

Return type

tones.tone.Samples

ptttl.audio.ptttl_to_wav(ptttl_data, wav_filename, amplitude=0.5, wavetype=0)

Convert a PTTTLData object to audio data and write it to a .wav file.

Parameters
  • ptttl_data (str) – PTTTL/RTTTL source text

  • wav_filename (str) – Filename for output .wav file

  • amplitude (float) – Output signal amplitude, between 0.0 and 1.0.

  • wavetype (int) – Waveform type for output signal. Must be one of tones.SINE_WAVE, tones.SQUARE_WAVE, tones.TRIANGLE_WAVE, or tones.SAWTOOTH_WAVE.

ptttl.audio.ptttl_to_wav_samples(ptttl_data, amplitude=0.5, wavetype=0)

Convert a PTTTLData object to a list of audio samples, packed into string and ready for writing to .wav files.

Parameters
  • ptttl_data (str) – PTTTL/RTTTL source text

  • amplitude (float) – Output signal amplitude, between 0.0 and 1.0.

  • wavetype (int) – Waveform type for output signal. Must be one of tones.SINE_WAVE, tones.SQUARE_WAVE, tones.TRIANGLE_WAVE, or tones.SAWTOOTH_WAVE.

Returns

list of audio samples

Return type

str

ptttl.parser module

class ptttl.parser.PTTTLData(bpm=123, default_octave=4, default_duration=8, default_vibrato_freq=7.0, default_vibrato_var=20.0)

Bases: object

Represents song data extracted from a PTTTL/RTTTL file. May contain multiple tracks, where each track is a list of PTTTLNote objects.

Variables
  • tracks ([[PTTTLNote]]) – List of tracks. Each track is a list of PTTTLNote objects.

  • bpm (float) – playback speed in BPM (beats per minute).

  • default_octave (int) – Default octave to use when none is specified

  • default_duration (int) – Default note duration to use when none is specified

  • default_vibrato_freq (float) – Default vibrato frequency when none is specified, in Hz

  • default_vibrato_var (float) – Default vibrato variance when none is specified, in Hz

add_track(notes)
class ptttl.parser.PTTTLNote(pitch, duration, vfreq=None, vvar=None)

Bases: object

Represents a single musical note, with a pitch and duration

Variables
  • pitch (float) – Note pitch in Hz

  • duration (float) – Note duration in seconds

  • vfreq (float) – Vibrato frequency in Hz

  • vvar (float) – Vibrato variance from main pitch in Hz

has_vibrato()

Returns True if vibrato frequency and variance are non-zero

Returns

True if vibrato is non-zero

Return type

bool

class ptttl.parser.PTTTLParser

Bases: object

Converts PTTTL/RTTTL source text to a PTTTLData object.

parse(ptttl_string)

Extracts song data from ptttl/rtttl source data.

Parameters

ptttl_string (str) – PTTTL/RTTTL source text.

Returns

Song data extracted from source text.

Return type

PTTTLData

exception ptttl.parser.PTTTLSyntaxError

Bases: Exception

Raised by PTTTLParser when ptttl data is malformed and cannot be parsed

exception ptttl.parser.PTTTLValueError

Bases: Exception

Raised by PTTTLParser when ptttl data parsing completes, but an invalid configuration value or note value was seen.

Module contents