Export and Output API documentation¶
Console audio output¶
This module includes functions to play sounds on the console
- xenharmlib.play.play(playable: Iterable[HasFrequency] | HasFrequency | Iterable[Frequency] | Frequency, duration: float = 0.5, play_as_chord: bool = False, sample_rate: int = 22050)¶
Renders an object into a sine wave sound and plays it
- Parameters:
playable – The playable object. Can be a pitch, note, frequency, a list of the aforementioned - or a scale.
duration – (optional, default is 0.5) The number of seconds a single sound should be played
play_as_chord – (optional, default False). If set to True items in collections of playable objects will be mixed instead of put after another.
sample_rate – (optional, default 22050) The sample rate of the output data
Audio export¶
This module includes functions to render frequencies of objects as sine waves and export them as wavfile
- xenharmlib.export.audio.concat_audio_chunks(chunks: List)¶
Concatenates a list of numpy arrays including raw audio data.
- Parameters:
chunks – A list of numpy arrays containing raw audio data
- xenharmlib.export.audio.export_wav(filename: str, playable: Iterable[HasFrequency] | HasFrequency | Iterable[Frequency] | Frequency, duration: float = 0.5, play_as_chord: bool = False, sample_rate: int = 22050)¶
This function exports a playable object as a wav file
- Parameters:
filename – Target filename to export data to
playable – The playable object. Can be a pitch, note, frequency, a list of the aforementioned - or a scale.
duration – (optional, default is 0.5) The number of seconds a single sound should be played
play_as_chord – (optional, default False). If set to True items in collections of playable objects will be mixed instead of put after another.
sample_rate – (optional, default 22050) The sample rate of the output data
- xenharmlib.export.audio.freq_to_raw_sine_audio(frequency: Frequency, duration: float = 0.5, sample_rate: int = 22050)¶
Returns a raw audio byte stream as a numpy array for a given frequency by using a generic sine wave
- Parameters:
frequency – The frequency of the sine wave
duration – The duration in seconds
sample_rate – The sample rate of the raw audio (optional, default is 22050)
- xenharmlib.export.audio.mix_audio_chunks(chunks: List)¶
Mixes a list of numpy arrays including raw audio data.
- Parameters:
chunks – A list of numpy arrays containing raw audio data
- xenharmlib.export.audio.pitch_like_to_raw_sine_audio(pitch_like: HasFrequency, duration: float = 0.5, sample_rate: int = 22050)¶
Returns a raw audio byte stream as a numpy array for a given pitch-like object (e.g. a note or a pitch object) by using a generic sine wave
- Parameters:
pitch_like – An object with a frequency property
duration – The duration in seconds
sample_rate – The sample rate of the raw audio (optional, default is 22050)
- xenharmlib.export.audio.playable_to_raw_sine_audio(playable: Iterable[HasFrequency] | HasFrequency | Iterable[Frequency] | Frequency, duration: float = 0.5, play_as_chord: bool = False, sample_rate: int = 22050)¶
Returns a raw audio byte stream as a numpy array for a given playable object (a frequency, frequency list, note, pitch, note scale, pitch scale, note list, pitch list)
- Parameters:
playable – A playable object
duration – (optional, default is 0.5) The number of seconds a single sound should be played
sample_rate – The sample rate of the raw audio (optional, default is 22050)
- xenharmlib.export.audio.tone_obj_to_raw_sine_audio(tone_obj: Frequency | HasFrequency, duration: float = 0.5, sample_rate: int = 22050)¶
Returns a raw audio byte stream as a numpy array for a given tone object (a frequency, note or pitch) by using a generic sine wave
- Parameters:
frequency – The frequency of the sinewave
duration – The duration in seconds
sample_rate – The sample rate of the raw audio (optional, default is 22050)
Scala file export¶
This module includes functions to export scales into the Scala .scl file format, see https://www.huygens-fokker.org/scala/scl_format.html
- xenharmlib.export.scl.export_scl(filename: str, scale: PeriodicPitchScaleLike, title: str | None = None, ensure_period: bool = False)¶
This function exports a pitch/note scale to a .scl file
- Parameters:
filename – Target filename to export data to
scale – A pitch scale or note scale
title – Title of the file (optional, defaults to the object representation of the scale)
ensure_period – (optional, default False). If set to True the function will make sure that the first and the last item in the scale have the same pitch class. If this is not the case the function will append the next highest pitch/note that is equivalent to the first.