### Install audiotsm with streaming support Source: https://audiotsm.readthedocs.io/en/latest/index.html Install audiotsm with support for real-time playback and examples. ```bash pip install audiotsm[stream] ``` -------------------------------- ### Install audiotsm with pip Source: https://audiotsm.readthedocs.io/en/latest/index.html Install the latest version of the audiotsm library using pip. ```bash pip install audiotsm ``` -------------------------------- ### Install audiotsm with GStreamer support Source: https://audiotsm.readthedocs.io/en/latest/index.html Install audiotsm with GStreamer plugins, requiring PyGObject and python-gst. ```bash pip install audiotsm[gstreamer] ``` -------------------------------- ### Phase Locking Strategies Source: https://audiotsm.readthedocs.io/en/latest/tsm.html Enumeration of phase locking strategies. Use `from_str()` to get a strategy by its name. ```python `IDENTITY`_= 1_ Identity phase locking. ``` ```python `NONE`_= 0_ No phase locking. ``` ```python _classmethod_`from_str`(_name_) Returns a phase locking strategy given its name. ``` -------------------------------- ### Seek Gstreamer Pipeline to Change Playback Speed Source: https://audiotsm.readthedocs.io/en/latest/gstreamer.html Change the playback rate of a Gstreamer pipeline by sending a seek event. This example sets the speed to 0.5. ```python speed = 0.5 pipeline.seek(speed, Gst.Format.BYTES, Gst.SeekFlags.FLUSH, Gst.SeekType.NONE, -1, Gst.SeekType.NONE, -1) ``` -------------------------------- ### Gstreamer Plugin Initialization Source: https://audiotsm.readthedocs.io/en/latest/gstreamer.html How to import and instantiate an audiotsm Gstreamer filter. ```APIDOC ## Initialization ### Description Import the desired TSM module and create the filter element using Gst.ElementFactory. ### Request Example ```python import audiotsm.gstreamer.phasevocoder tsm = Gst.ElementFactory.make("audiotsm-phase-vocoder") ``` ``` -------------------------------- ### Wav File I/O Classes Source: https://audiotsm.readthedocs.io/en/latest/io.html Classes for reading from and writing to wav files. ```APIDOC ## WavReader ### Description A Reader allowing to use a wav file as input of a TSM object. ### Parameters - **filename** (str) - Required - The name of an existing wav file. ## WavWriter ### Description A Writer allowing to use a wav file as output of a TSM object. ### Parameters - **filename** (str) - Required - The name of the wav file. - **channels** (int) - Required - The number of channels of the signal. - **samplerate** (int) - Required - The sampling rate of the signal. ``` -------------------------------- ### audiotsm.gstreamer.wsola Source: https://audiotsm.readthedocs.io/en/latest/genindex.html WSOLA algorithm implementation. ```APIDOC ## WSOLA ### Description Class implementing the WSOLA algorithm in audiotsm.gstreamer.wsola. ## wsola() ### Description Function available in the audiotsm module. ``` -------------------------------- ### Import Gstreamer Phase Vocoder Module Source: https://audiotsm.readthedocs.io/en/latest/gstreamer.html Import the Gstreamer phase vocoder module to use its functionalities. ```python import audiotsm.gstreamer.phasevocoder ``` -------------------------------- ### audiotsm.io.wav Source: https://audiotsm.readthedocs.io/en/latest/genindex.html Classes for reading and writing WAV files. ```APIDOC ## WavReader ### Description Class for reading WAV files. ## WavWriter ### Description Class for writing WAV files. ``` -------------------------------- ### Window Functions Module Source: https://audiotsm.readthedocs.io/en/latest/internalapi.html Utilities for applying and generating window functions for digital signal processing. ```APIDOC ## audiotsm.utils.windows.apply(_buffer_ , _window_) ### Description Applies a window to a buffer. ### Method POST (or similar, depending on context) ### Endpoint N/A (Function in a module) ### Parameters #### Request Body - **buffer** (numpy.ndarray) - A matrix of shape (`m`, `n`), with `m` the number of channels and `n` the length of the buffer. - **window** (numpy.ndarray) - A numpy array of shape (`n`,). ## audiotsm.utils.windows.hanning(_length_) ### Description Returns a periodic Hanning window. Contrary to `numpy.hanning()`, which returns the symmetric Hanning window, `hanning()` returns a periodic Hanning window, which is better for spectral analysis. ### Method GET (or similar, depending on context) ### Endpoint N/A (Function in a module) ### Parameters #### Query Parameters - **length** (int) - The number of points of the Hanning window. ### Response #### Success Response (200) - **numpy.ndarray** - The window as a `numpy.ndarray` of shape (`length`,). ### Response Example ```json { "example": "numpy.ndarray of shape (length,)" } ``` ## audiotsm.utils.windows.product(_window1_ , _window2_) ### Description Returns the product of two windows. ### Method POST (or similar, depending on context) ### Endpoint N/A (Function in a module) ### Parameters #### Request Body - **window1** (numpy.ndarray or None) - A numpy array of shape (`n`,) or None. - **window2** (numpy.ndarray or None) - A numpy array of shape (`n`,) or None. ### Response #### Success Response (200) - **numpy.ndarray or None** - The product of the two windows. If one of the windows is equal to `None`, the other is returned, and if the two are equal to `None`, `None` is returned. ``` -------------------------------- ### Use WavWriter with a context manager Source: https://audiotsm.readthedocs.io/en/latest/io.html Ensures the wav file is properly closed after writing by using a with statement. ```python with WavWriter(filename, 2, 44100) as writer: # use writer... ``` -------------------------------- ### Basic Phase Vocoder Usage in Python Source: https://audiotsm.readthedocs.io/en/latest/index.html Reduce the speed of a WAV file by half using the phase vocoder procedure. Ensure input_filename and output_filename are defined. ```python from audiotsm import phasevocoder from audiotsm.io.wav import WavReader, WavWriter with WavReader(input_filename) as reader: with WavWriter(output_filename, reader.channels, reader.samplerate) as writer: tsm = phasevocoder(reader.channels, speed=0.5) tsm.run(reader, writer) ``` -------------------------------- ### Use WavReader with a context manager Source: https://audiotsm.readthedocs.io/en/latest/io.html Ensures the wav file is properly closed after processing by using a with statement. ```python with WavReader(filename) as reader: # use reader... ``` -------------------------------- ### Gstreamer Plugin Properties Source: https://audiotsm.readthedocs.io/en/latest/gstreamer.html Configuration properties for OLA, WSOLA, and Phase Vocoder plugins. ```APIDOC ## Plugin Properties ### Description Common and specific properties for TSM plugins. Properties are write-only and take effect on the next setup. ### Properties - **frame_length** (int) - The length of the frames. - **synthesis_hop** (int) - The number of samples between two consecutive synthesis frames. - **tolerance** (int) - (WSOLA only) The maximum number of samples that the analysis frame can be shifted. - **phase_locking** (str) - (Phase Vocoder only) The phase locking strategy. ``` -------------------------------- ### StreamWriter Source: https://audiotsm.readthedocs.io/en/latest/io.html Class for real-time audio playback. ```APIDOC ## StreamWriter ### Description A Writer allowing to play the output of a TSM object directly in real-time. ### Parameters - **channels** (int) - Required - The number of channels of the signal. - **samplerate** (int) - Required - The sampling rate of the signal. - **attrs** (dict) - Optional - Additional parameters for the underlying sounddevice.OutputStream. ``` -------------------------------- ### Class Method: from_str Source: https://audiotsm.readthedocs.io/en/latest/tsm.html Class method to retrieve a phase locking strategy by its name. ```APIDOC ## Class Method: from_str ### Description Returns a phase locking strategy given its name. ### Method `from_str(name)` ### Parameters - **name** (string) - Required - The name of the phase locking strategy. ``` -------------------------------- ### Create Gstreamer Audiotsm Filter Element Source: https://audiotsm.readthedocs.io/en/latest/gstreamer.html Create an audio filter element using Gst.ElementFactory.make with the specified plugin name. ```python tsm = Gst.ElementFactory.make("audiotsm-phase-vocoder") ``` -------------------------------- ### CBuffer Class Methods Source: https://audiotsm.readthedocs.io/en/latest/internalapi.html Methods for interacting with the CBuffer, including converting to an array and writing data. ```APIDOC ## CBuffer.to_array() ### Description Returns an array containing the same data as the `CBuffer`. ### Method GET (or similar, depending on context) ### Endpoint N/A (Method of a class instance) ### Response #### Success Response (200) - **numpy.ndarray** (numpy.ndarray) - A numpy array of shape (`m`, `n`), with `m` the number of channels and `n` the length of the buffer. ### Response Example ```json { "example": "numpy.ndarray" } ``` ## CBuffer.write(_buffer_) ### Description Writes as many samples from the `buffer` to the `CBuffer` as possible, and returns the number of samples that were read. The written samples are marked as ready to be read. ### Method POST (or similar, depending on context) ### Endpoint N/A (Method of a class instance) ### Parameters #### Request Body - **buffer** (numpy.ndarray) - A matrix of shape (`m`, `n`), where `m` is the number of channels and `n` is the length of the buffer, from which samples will be read. ### Response #### Success Response (200) - **int** - The number of samples that were written to the `CBuffer`. ### Response Example ```json { "example": "number of samples written" } ``` ### Error Handling - **ValueError**: Raised if the `CBuffer` and the `buffer` do not have the same number of channels. ## CBuffer.write_to(_writer_) ### Description Writes as many samples as possible to `writer`, deletes them from the `CBuffer`, and returns the number of samples that were written. The samples need to be marked as ready to be read with the `CBuffer.set_ready()` method in order to be read. This is done automatically by the `CBuffer.write()` and `CBuffer.read_from()` methods. ### Method POST (or similar, depending on context) ### Endpoint N/A (Method of a class instance) ### Parameters #### Request Body - **writer** (audiotsm.io.base.Writer) - A `audiotsm.io.base.Writer` object. ### Response #### Success Response (200) - **int** - The number of samples that were written to `writer`. ### Response Example ```json { "example": "number of samples written" } ``` ### Error Handling - **ValueError**: Raised if the `CBuffer` and `writer` do not have the same number of channels. ``` -------------------------------- ### AnalysisSynthesisTSM Class Source: https://audiotsm.readthedocs.io/en/latest/internalapi.html Provides a base class for real-time analysis-synthesis based audio time-scale modification procedures. ```APIDOC ## Class: AnalysisSynthesisTSM ### Description A TSM for real-time analysis-synthesis based time-scale modification procedures. It decomposes the input signal into frames, relocates them on the time axis, and optionally applies window functions and converters to reduce artifacts. ### Parameters #### Constructor Parameters - **converter** (Converter) - An object that implements the conversion of the analysis frames into synthesis frames. - **channels** (int) - The number of channels of the input signal. - **frame_length** (int) - The length of the frames. - **analysis_hop** (int) - The number of samples between two consecutive analysis frames. - **synthesis_hop** (int) - The number of samples between two consecutive synthesis frames. - **analysis_window** (numpy.ndarray) - A window applied to the analysis frames. - **synthesis_window** (numpy.ndarray) - A window applied to the synthesis frames. - **delta_before** (int) - Optional. The number of samples preceding an analysis frame that the converter requires (default: 0). - **delta_after** (int) - Optional. The number of samples following an analysis frame that the converter requires (default: 0). ``` -------------------------------- ### TSM Object Methods Source: https://audiotsm.readthedocs.io/en/latest/tsm.html Abstract class for real-time audio time-scale modification. Use the `run()` method for most TSM procedures. Call `clear()` before processing a new file or seeking. ```python clear() Clears the state of the `TSM` object, making it ready to be used on another signal (or another part of a signal). This method should be called before processing a new file, or seeking to another part of a signal. ``` ```python flush_to(_writer_) Writes as many output samples as possible to `writer`, assuming that there are no remaining samples that will be added to the input (i.e. that the `write_to()` method will not be called), and returns the number of samples that were written. Parameters:| **writer** – a `audiotsm.io.base.Writer`. ---|--- Returns:| a tuple (`n`, `finished`), with: * `n` the number of samples that were written to `writer` * `finished` a boolean that is `True` when there are no samples remaining to flush. Return type:| (int, bool) ``` ```python get_max_output_length(_input_length_) Returns the maximum number of samples that will be written to the output given the numver of samples of the input. Parameters:| **input_length** (_int_) – the number of samples of the input. ---|--- Returns:| the maximum number of samples that will be written to the output. ``` ```python read_from(_reader_) Reads as many samples as possible from `reader`, processes them, and returns the number of samples that were read. Parameters:| **reader** – a `audiotsm.io.base.Reader`. ---|--- Returns:| the number of samples that were read from `reader`. ``` ```python run(_reader_ , _writer_ , _flush=True_) Runs the TSM procedure on the content of `reader` and writes the output to `writer`. Parameters:| * **reader** – a `audiotsm.io.base.Reader`. * **writer** – a `audiotsm.io.base.Writer`. * **flush** (_bool_ _,__optional_) – `True` if there is no more data to process. ---|--- ``` ```python set_speed(_speed_) Sets the speed ratio. Parameters:| **speed** (_float_) – the speed ratio by which the speed of the signal will be multiplied (for example, if `speed` is set to 0.5, the output signal will be half as fast as the input signal). ---|--- ``` ```python write_to(_writer_) Writes as many result samples as possible to `writer`. Parameters:| **writer** – a `audiotsm.io.base.Writer`. ---|--- Returns:| a tuple (`n`, `finished`), with: * `n` the number of samples that were written to `writer` * `finished` a boolean that is `True` when there are no samples remaining to write. In this case, the `read_from()` method should be called to add new input samples, or, if there are no remaining input samples, the `flush_to()` method should be called to get the last output samples. Return type:| (int, bool) ``` -------------------------------- ### TSM Class Methods Source: https://audiotsm.readthedocs.io/en/latest/tsm.html This section details the methods available for the abstract TSM class, used for real-time audio time-scale modification. ```APIDOC ## TSM Class Methods ### Description Provides methods for real-time audio time-scale modification procedures. ### Methods #### `clear()` ##### Description Clears the state of the `TSM` object, making it ready to be used on another signal. #### `flush_to(writer)` ##### Description Writes as many output samples as possible to `writer`, assuming no remaining input samples. ##### Parameters - **writer** (audiotsm.io.base.Writer) - Required - The writer object to which output samples will be written. ##### Returns - **n** (int) - The number of samples written. - **finished** (bool) - True if no samples remain. #### `get_max_output_length(input_length)` ##### Description Returns the maximum number of output samples for a given number of input samples. ##### Parameters - **input_length** (int) - Required - The number of samples in the input. ##### Returns - (int) - The maximum number of output samples. #### `read_from(reader)` ##### Description Reads samples from `reader`, processes them, and returns the number of samples read. ##### Parameters - **reader** (audiotsm.io.base.Reader) - Required - The reader object from which to read input samples. ##### Returns - (int) - The number of samples read. #### `run(reader, writer, flush=True)` ##### Description Runs the TSM procedure on the content of `reader` and writes the output to `writer`. ##### Parameters - **reader** (audiotsm.io.base.Reader) - Required - The reader object for input samples. - **writer** (audiotsm.io.base.Writer) - Required - The writer object for output samples. - **flush** (bool) - Optional - True if there is no more data to process. #### `set_speed(speed)` ##### Description Sets the speed ratio for time-scale modification. ##### Parameters - **speed** (float) - Required - The speed ratio. A value of 0.5 means the output signal will be half as fast as the input. #### `write_to(writer)` ##### Description Writes as many result samples as possible to `writer`. ##### Parameters - **writer** (audiotsm.io.base.Writer) - Required - The writer object to which output samples will be written. ##### Returns - **n** (int) - The number of samples written. - **finished** (bool) - True if no samples remain to write. ``` -------------------------------- ### Use StreamWriter with a context manager Source: https://audiotsm.readthedocs.io/en/latest/io.html Ensures the audio stream is properly stopped after playback by using a with statement. ```python with WavWriter(2, 44100) as writer: # use writer... ``` -------------------------------- ### Synthesis Frame Spacing Illustration Source: https://audiotsm.readthedocs.io/en/latest/internalapi.html Illustrates how synthesis frames are spaced differently from analysis frames to achieve time-scale modification. ```text <--------frame_length--------><----synthesis_hop----> Frame 1: [~~~~~~~~~~~~~~~~~~~~~~~~~~~~] Frame 2: [~~~~~~~~~~~~~~~~~~~~~~~~~~~~] Frame 3: [~~~~~~~~~~~~~~~~~~~~~~~~~~~~] ... ``` -------------------------------- ### Audiotsm Library Index Source: https://audiotsm.readthedocs.io/en/latest/genindex.html This section lists the main modules and classes available in the Audiotsm library, organized alphabetically. ```APIDOC ## Audiotsm Library Modules and Classes This documentation provides an index of the Audiotsm library's components, categorized alphabetically. ### Modules - `audiotsm` - `audiotsm.base.analysis_synthesis` - `audiotsm.base.tsm` - `audiotsm.gstreamer` - `audiotsm.gstreamer.base` - `audiotsm.gstreamer.ola` - `audiotsm.gstreamer.phasevocoder` - `audiotsm.gstreamer.wsola` - `audiotsm.io` - `audiotsm.io.array` - `audiotsm.io.base` - `audiotsm.io.stream` - `audiotsm.io.wav` - `audiotsm.utils` - `audiotsm.utils.windows` ### Classes - `audiotsm.utils.CBuffer` - `audiotsm.base.analysis_synthesis.AnalysisSynthesisTSM` - `audiotsm.io.array.ArrayReader` - `audiotsm.io.array.ArrayWriter` - `audiotsm.io.array.FixedArrayWriter` - `audiotsm.base.analysis_synthesis.Converter` - `audiotsm.gstreamer.base.GstTSM` - `audiotsm.gstreamer.ola.OLA` - `audiotsm.utils.NormalizeBuffer` - `audiotsm.PhaseLocking` - `audiotsm.gstreamer.phasevocoder.PhaseVocoder` - `audiotsm.base.tsm.TSM` - `audiotsm.io.stream.StreamWriter` - `audiotsm.io.wav.WavReader` - `audiotsm.io.wav.WavWriter` ### Methods and Attributes #### `audiotsm.utils.CBuffer` - `add()` - `divide()` - `length` (attribute) - `peek()` - `ready` (attribute) - `read()` - `read_from()` - `remaining_length` (attribute) - `remove()` - `right_pad()` - `set_ready()` - `to_array()` #### `audiotsm.base.analysis_synthesis.AnalysisSynthesisTSM` - `clear()` #### `audiotsm.io.array.ArrayReader` - (No specific methods listed beyond base Reader) #### `audiotsm.io.array.ArrayWriter` - `data` (attribute) #### `audiotsm.io.array.FixedArrayWriter` - (No specific methods listed) #### `audiotsm.base.analysis_synthesis.Converter` - `clear()` - `convert_frame()` - `set_analysis_hop()` #### `audiotsm.gstreamer.base.GstTSM` - `create_tsm()` (class method) - `do_sink_event()` - `do_transform()` - `do_transform_size()` - `plugin_init()` (class method) - `register()` (class method) #### `audiotsm.gstreamer.ola.OLA` - `frame_length` (attribute) - `plugin_name` (attribute) - `synthesis_hop` (attribute) #### `audiotsm.utils.NormalizeBuffer` - `add()` - `remove()` - `to_array()` #### `audiotsm.PhaseLocking` - `IDENTITY` (attribute) - `NONE` (attribute) - `from_str()` (class method) #### `audiotsm.gstreamer.phasevocoder.PhaseVocoder` - `frame_length` (attribute) - `phase_locking` (attribute) - `plugin_name` (attribute) - `synthesis_hop` (attribute) #### `audiotsm.base.tsm.TSM` - `clear()` - `flush_to()` - `get_max_output_length()` - `read_from()` - `run()` - `set_speed()` #### `audiotsm.io.stream.StreamWriter` - `stop()` #### `audiotsm.io.wav.WavReader` - `close()` - `samplerate` (attribute) - `samplewidth` (attribute) #### `audiotsm.io.wav.WavWriter` - `close()` #### `audiotsm.io.base.Reader` - `channels` (attribute) - `empty` (attribute) - `read()` - `skip()` #### `audiotsm.io.base.Writer` - `channels` (attribute) #### `audiotsm.utils.windows` module functions - `apply()` - `hanning()` - `product()` #### Module functions - `ola()` (in module `audiotsm`) - `phasevocoder()` (in module `audiotsm`) - `audioformatinfo_to_dtype()` (in module `audiotsm.gstreamer.base`) ``` -------------------------------- ### Array I/O Classes Source: https://audiotsm.readthedocs.io/en/latest/io.html Classes for reading from and writing to numpy arrays. ```APIDOC ## ArrayReader ### Description A Reader allowing to use numpy.ndarray as input of a TSM object. ### Parameters - **data** (numpy.ndarray) - Required - A matrix of shape (m, n), with m the number of channels and n the length of the buffer. ## ArrayWriter ### Description A Writer allowing to get the output of a TSM object as a numpy.ndarray. ### Parameters - **channels** (int) - Required - The number of channels of the signal. ## FixedArrayWriter ### Description A Writer allowing to use numpy.ndarray as output of a TSM object with a fixed-size buffer. ### Parameters - **data** (numpy.ndarray) - Required - A matrix of shape (m, n) representing the fixed-size buffer. ``` -------------------------------- ### audiotsm.io.base.Writer Source: https://audiotsm.readthedocs.io/en/latest/genindex.html Base class for writers and associated methods. ```APIDOC ## Writer ### Description Base class for writers in audiotsm.io.base. ## write() ### Description Method to write data, available in audiotsm.io.base.Writer and audiotsm.utils.CBuffer. ``` -------------------------------- ### Analysis-Synthesis Frame Illustration Source: https://audiotsm.readthedocs.io/en/latest/internalapi.html Illustrates the concept of analysis frames and their spacing in an analysis-synthesis TSM procedure. ```text <--------frame_length--------><-analysis_hop-> Frame 1: [~~~~~~~~~~~~~~~~~~~~~~~~~~~~] Frame 2: [~~~~~~~~~~~~~~~~~~~~~~~~~~~~] Frame 3: [~~~~~~~~~~~~~~~~~~~~~~~~~~~~] ... ``` -------------------------------- ### CBuffer Class Source: https://audiotsm.readthedocs.io/en/latest/internalapi.html The CBuffer class represents a circular buffer for storing multichannel audio data. It has a maximum length and supports operations like writing, reading, padding, and adding/dividing samples. ```APIDOC ## Class: CBuffer ### Description A circular buffer used to store multichannel audio data. It can be seen as a variable-size buffer whose length is bounded by `max_length`. The `CBuffer.write()` and `CBuffer.right_pad()` methods allow to add samples at the end of the buffer, while the `CBuffer.read()` and `CBuffer.remove()` methods allow to remove samples from the beginning of the buffer. Contrary to the samples added by the `CBuffer.write()` and `CBuffer.read_from()`, those added by the `CBuffer.right_pad()` method are considered not to be ready to be read. Effectively, this means that they can be modified by the `CBuffer.add()` and `CBuffer.divide()` methods, but have to be marked as ready to be read with the `CBuffer.set_ready()` method before being read with the `CBuffer.peek()`, `CBuffer.read()`, or `CBuffer.write_to()` methods. ### Parameters * **channels** (int) - The number of channels of the buffer. * **max_length** (int) - The maximum length of the buffer (i.e. the maximum number of samples that can be stored in each channel). ### Methods #### `add(buffer)` Adds a `buffer` element-wise to the `CBuffer`. * **Parameters**: * **buffer** (numpy.ndarray) - A matrix of shape (`m`, `n`), with `m` the number of channels and `n` the length of the buffer. * **Raises**: * **ValueError** - If the `CBuffer` and the `buffer` do not have the same number of channels or the `CBuffer` is smaller than the `buffer` (`self.length < n`). #### `divide(array)` Divides each channel of the `CBuffer` element-wise by the `array`. * **Parameters**: * **array** (numpy.ndarray) - An array of shape (`n`,). * **Raises**: * **ValueError** - If the length of the `CBuffer` is smaller than the length of the array (`self.length < n`). #### `length` (property) The number of samples of each channel of the `CBuffer`. #### `peek(buffer)` Reads as many samples from the `CBuffer` as possible, without removing them from the `CBuffer`, writes them to the `buffer`, and returns the number of samples that were read. The samples need to be marked as ready to be read with the `CBuffer.set_ready()` method in order to be read. This is done automatically by the `CBuffer.write()` and `CBuffer.read_from()` methods. * **Parameters**: * **buffer** (numpy.ndarray) - A matrix of shape (`m`, `n`), with `m` the number of channels and `n` the length of the buffer, where the samples will be written. * **Returns**: * The number of samples that were read from the `CBuffer`. * **Raises**: * **ValueError** - If the `CBuffer` and the `buffer` do not have the same number of channels. #### `read(buffer)` Reads as many samples from the `CBuffer` as possible, removes them from the `CBuffer`, writes them to the `buffer`, and returns the number of samples that were read. The samples need to be marked as ready to be read with the `CBuffer.set_ready()` method in order to be read. This is done automatically by the `CBuffer.write()` and `CBuffer.read_from()` methods. * **Parameters**: * **buffer** (numpy.ndarray) - A matrix of shape (`m`, `n`), with `m` the number of channels and `n` the length of the buffer, where the samples will be written. * **Returns**: * The number of samples that were read from the `CBuffer`. * **Raises**: * **ValueError** - If the `CBuffer` and the `buffer` do not have the same number of channels. #### `read_from(reader)` Reads as many samples as possible from `reader`, writes them to the `CBuffer`, and returns the number of samples that were read. The written samples are marked as ready to be read. * **Parameters**: * **reader** - A `audiotsm.io.base.Reader`. * **Returns**: * The number of samples that were read from `reader`. * **Raises**: * **ValueError** - If the `CBuffer` and `reader` do not have the same number of channels. #### `ready` (property) The number of samples that can be read. #### `remaining_length` (property) The number of samples that can be added to the `CBuffer`. #### `remove(n)` Removes the first `n` samples of the `CBuffer`, preventing them to be read again, and leaving more space for new samples to be written. * **Parameters**: * **n** (int) - The number of samples to remove. * **Returns**: * The number of samples that were removed. #### `right_pad(n)` Add zeros at the end of the `CBuffer`. The added samples are not marked as ready to be read. The `CBuffer.set_ready()` will need to be called in order to be able to read them. * **Parameters**: * **n** (int) - The number of zeros to add. * **Raises**: * **ValueError** - If there is not enough space to add the zeros. #### `set_ready(n)` Mark the next `n` samples as ready to be read. * **Parameters**: * **n** (int) - The number of samples to mark as ready to be read. * **Raises**: * **ValueError** - If there is less than `n` samples that are not ready yet. ``` -------------------------------- ### Converter Class Source: https://audiotsm.readthedocs.io/en/latest/internalapi.html Base class for objects that convert analysis frames into synthesis frames. ```APIDOC ## Class: Converter ### Description A base class for objects implementing the conversion of analysis frames into synthesis frames. ### Methods #### clear() Clears the state of the Converter, making it ready to be used on another signal. #### convert_frame(analysis_frame) Converts an analysis frame into a synthesis frame. ##### Parameters - **analysis_frame** (numpy.ndarray) - A matrix of shape (m, delta_before + frame_length + delta_after), with m the number of channels, containing the analysis frame and some samples before and after. `analysis_frame[:, delta_before:-delta_after]` contains the actual analysis frame. ##### Returns - numpy.ndarray - A synthesis frame represented as a matrix of shape (m, frame_length), with m the number of channels. #### set_analysis_hop(analysis_hop) Changes the value of the analysis hop. This is called by the `set_speed()` method. ``` -------------------------------- ### Phase Locking Strategies Source: https://audiotsm.readthedocs.io/en/latest/tsm.html Enumeration of phase locking strategies available in the audiotsm library. ```APIDOC ## Phase Locking Strategies ### Description Enumeration of phase locking strategies. ### Strategies #### `IDENTITY` ##### Description Identity phase locking. #### `NONE` ##### Description No phase locking. ``` -------------------------------- ### GstTSM Class Source: https://audiotsm.readthedocs.io/en/latest/internalapi.html Base class for implementing Gstreamer TSM plugins. ```APIDOC ## GstTSM Class ### Description Base class for Gstreamer TSM plugins. Subclasses must implement `create_tsm()` and define `__gstmetadata__` and `plugin_name`. ### Methods - **create_tsm(channels)**: Returns the TSM object used by the audio filter. - **do_sink_event(event)**: Sink pad event handler. - **do_transform(in_buffer, out_buffer)**: Processes input data through the TSM object. - **do_transform_size(direction, caps, size, othercaps)**: Returns the size of the output buffer. - **plugin_init(plugin)**: Initializes the plugin. - **register()**: Registers the plugin for use with Gst.ElementFactory.make. ``` -------------------------------- ### audiotsm.io.base.Writer Source: https://audiotsm.readthedocs.io/en/latest/io.html An abstract class for the output of a TSM object. It defines methods for writing audio data and managing the writing process. ```APIDOC ## Class: audiotsm.io.base.Writer ### Description An abstract class for the output of a TSM object. ### Attributes - **channels** (int) - The number of channels of the Writer. ### Methods #### write(_buffer_) Write as many samples from the Writer as possible from buffer, and returns the number of samples that were written. - **Parameters**: - **buffer** (numpy.ndarray) - A matrix of shape (m, n), where m is the number of channels and n is the length of the buffer, where the samples will be read. - **Returns**: - int - The number of samples that were written. It should always be equal to the length of the buffer, except when there is no more space in the Writer. - **Raises**: - ValueError - If the Writer and the buffer do not have the same number of channels. ``` -------------------------------- ### audiotsm.io.base.Reader Source: https://audiotsm.readthedocs.io/en/latest/io.html An abstract class for the input of a TSM object. It defines methods for reading audio data and managing the reading process. ```APIDOC ## Class: audiotsm.io.base.Reader ### Description An abstract class for the input of a TSM object. ### Attributes - **channels** (int) - The number of channels of the Reader. - **empty** (bool) - True if there is no more data to read. ### Methods #### read(_buffer_) Reads as many samples from the Reader as possible, write them to buffer, and returns the number of samples that were read. - **Parameters**: - **buffer** (numpy.ndarray) - A matrix of shape (m, n), where m is the number of channels and n is the length of the buffer, where the samples will be written. - **Returns**: - int - The number of samples that were read. It should always be equal to the length of the buffer, except when there is no more values to be read. - **Raises**: - ValueError - If the Reader and the buffer do not have the same number of channels. #### skip(_n_) Try to skip `n` samples, and returns the number of samples that were actually skipped. - **Parameters**: - **n** (int) - The number of samples to skip. - **Returns**: - int - The number of samples that were actually skipped. ``` -------------------------------- ### audiotsm.base.tsm.TSM Source: https://audiotsm.readthedocs.io/en/latest/genindex.html Time-scale modification methods. ```APIDOC ## write_to() ### Description Method to write output, available in audiotsm.base.tsm.TSM and audiotsm.utils.CBuffer. ``` -------------------------------- ### audioformatinfo_to_dtype Source: https://audiotsm.readthedocs.io/en/latest/internalapi.html Utility function to convert GstAudio.AudioFormatInfo to a numpy data type. ```APIDOC ## audioformatinfo_to_dtype(info) ### Description Return the data type corresponding to a GstAudio.AudioFormatInfo object. ### Parameters - **info** (GstAudio.AudioFormatInfo) - Required - The audio format info object. ### Returns - **dtype** (numpy.dtype) - The corresponding data type for use in numpy functions. ``` -------------------------------- ### WSOLA Gstreamer Plugin Name Source: https://audiotsm.readthedocs.io/en/latest/gstreamer.html The plugin name for the WSOLA (Waveform Similarity Overlap-Add) Gstreamer audio filter, used when creating the element with Gst.ElementFactory.make. ```python plugin_name = 'audiotsm-wsola' ``` -------------------------------- ### Phase Vocoder Gstreamer Plugin Name Source: https://audiotsm.readthedocs.io/en/latest/gstreamer.html The plugin name for the Phase Vocoder Gstreamer audio filter, used when creating the element with Gst.ElementFactory.make. ```python plugin_name = 'audiotsm-phase-vocoder' ``` -------------------------------- ### audiotsm.wsola Source: https://audiotsm.readthedocs.io/en/latest/tsm.html Returns a TSM object implementing the WSOLA (Waveform Similarity-based Overlap-Add) time-scale modification procedure. An improvement over OLA, suitable for most cases. ```APIDOC ## audiotsm.wsola ### Description Returns a `TSM` object implementing the WSOLA (Waveform Similarity-based Overlap-Add) time-scale modification procedure. This is an improvement over OLA and generally provides good results. ### Method `audiotsm.wsola` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **channels** (int) – the number of channels of the input signal. * **speed** (float, optional) – the speed ratio by which the speed of the signal will be multiplied (e.g., 0.5 for half speed). Defaults to 1.0. * **frame_length** (int, optional) – the length of the frames. Defaults to 1024. * **analysis_hop** (int, optional) – the number of samples between two consecutive analysis frames (`speed * synthesis_hop` by default). If `analysis_hop` is set, the `speed` parameter will be ignored. * **synthesis_hop** (int, optional) – the number of samples between two consecutive synthesis frames (`frame_length // 2` by default). * **tolerance** (int) – the maximum number of samples that the analysis frame can be shifted. ### Returns a `audiotsm.base.tsm.TSM` object ``` -------------------------------- ### NormalizeBuffer Class Source: https://audiotsm.readthedocs.io/en/latest/internalapi.html A mono-channel circular buffer used for normalizing audio buffers. ```APIDOC ## NormalizeBuffer(_length_) ### Description A `NormalizeBuffer` is a mono-channel circular buffer, used to normalize audio buffers. ### Parameters #### Request Body - **length** (int) - The length of the `NormalizeBuffer`. ## NormalizeBuffer.add(_window_) ### Description Adds a window element-wise to the `NormalizeBuffer`. ### Method POST (or similar, depending on context) ### Endpoint N/A (Method of a class instance) ### Parameters #### Request Body - **window** (numpy.ndarray) - An array of shape (`n`,). ### Error Handling - **ValueError**: Raised if the window is larger than the buffer (`n > self.length`). ## NormalizeBuffer.length ### Description Gets the length of the CBuffer. ### Method GET (or similar, depending on context) ### Endpoint N/A (Property of a class instance) ## NormalizeBuffer.remove(_n_) ### Description Removes the first `n` values of the `NormalizeBuffer`. ### Method DELETE (or similar, depending on context) ### Endpoint N/A (Method of a class instance) ### Parameters #### Request Body - **n** (int) - The number of values to remove. ## NormalizeBuffer.to_array(_start=0_ , _end=None_) ### Description Returns an array containing the same data as the `NormalizeBuffer`, from index `start` (included) to index `end` (excluded). ### Method GET (or similar, depending on context) ### Endpoint N/A (Method of a class instance) ### Parameters #### Query Parameters - **start** (int) - Optional. The starting index (inclusive). Defaults to 0. - **end** (int) - Optional. The ending index (exclusive). Defaults to None. ### Response #### Success Response (200) - **numpy.ndarray** (numpy.ndarray) - The array containing the data from the `NormalizeBuffer`. ``` -------------------------------- ### OLA Gstreamer Plugin Name Source: https://audiotsm.readthedocs.io/en/latest/gstreamer.html The plugin name for the OLA (Overlap-Add) Gstreamer audio filter, used when creating the element with Gst.ElementFactory.make. ```python plugin_name = 'audiotsm-ola' ``` -------------------------------- ### audiotsm.phasevocoder Source: https://audiotsm.readthedocs.io/en/latest/tsm.html Returns a TSM object implementing the phase vocoder time-scale modification procedure. Recommended for most cases with default parameters. ```APIDOC ## audiotsm.phasevocoder ### Description Returns a `TSM` object implementing the phase vocoder time-scale modification procedure. This procedure is recommended for most cases when using default parameters. ### Method `audiotsm.phasevocoder` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **channels** (int) – the number of channels of the input signal. * **speed** (float, optional) – the speed ratio by which the speed of the signal will be multiplied (e.g., 0.5 for half speed). Defaults to 1.0. * **frame_length** (int, optional) – the length of the frames. Defaults to 2048. * **analysis_hop** (int, optional) – the number of samples between two consecutive analysis frames (`speed * synthesis_hop` by default). If `analysis_hop` is set, the `speed` parameter will be ignored. * **synthesis_hop** (int, optional) – the number of samples between two consecutive synthesis frames (`frame_length // 4` by default). * **phase_locking** (PhaseLocking, optional) – a phase locking strategy. ### Returns a `audiotsm.base.tsm.TSM` object ``` -------------------------------- ### audiotsm.ola Source: https://audiotsm.readthedocs.io/en/latest/tsm.html Returns a TSM object implementing the OLA (Overlap-Add) time-scale modification procedure. Suitable for percussive audio signals. ```APIDOC ## audiotsm.ola ### Description Returns a `TSM` object implementing the OLA (Overlap-Add) time-scale modification procedure. ### Method `audiotsm.ola` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **channels** (int) – the number of channels of the input signal. * **speed** (float, optional) – the speed ratio by which the speed of the signal will be multiplied (e.g., 0.5 for half speed). Defaults to 1.0. * **frame_length** (int, optional) – the length of the frames. Defaults to 256. * **analysis_hop** (int, optional) – the number of samples between two consecutive analysis frames (`speed * synthesis_hop` by default). If `analysis_hop` is set, the `speed` parameter will be ignored. * **synthesis_hop** (int, optional) – the number of samples between two consecutive synthesis frames (`frame_length // 2` by default). ### Returns a `audiotsm.base.tsm.TSM` object ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.