Data

class untwist.data.Signal[source]

Time domain signal. Layout is one column per channel.

samples: ndarray
Signal data.
sample_rate: int
Sample rate in samples / second.
as_ndarray()[source]

Return the data as ndarray again

check_mono()[source]

Utility for ensuring the signal is mono (one channel)

num_channels

Number of channels

num_frames

Number of frames (samples)

class untwist.data.Wave(samples, sample_rate)[source]

Audio waveform signal.

samples: ndarray
Signal data.
sample_rate: int
Sample rate in samples / second.
duration
normalize()[source]

Normalize by maximum amplitude.

play(stop_func=None)[source]

Play the sound with the current audio driver.

stop_func: function
Function to execute when the sound ends.
plot()[source]

Plot the waveofrm using matplotlib.

classmethod read(filename)[source]

Read an audio file (only wav is supported).

filename: string
Path to the wav file.
classmethod record(max_seconds=10, num_channels=2, sr=44100, stop_func=None)[source]
stop()[source]

Stop playback if playing.

write(filename)[source]

Write the data to an audio file (only wav is supported).

filename: string
Path to the wav file.
zero_pad(start_frames, end_frames=0)[source]

Pad with zeros at the start and/or end

start_frames: int
Number of zeros at the start.
end_frames: int
Number of zeros at the end.
class untwist.data.Spectrum[source]

Audio spectrum complex signal.

magnitude()[source]

Return the magnitude spectrum.

phase()[source]

Return the phase spectrum.

plot()[source]

Plot magnitude and phase.

class untwist.data.Spectrogram[source]

Complex audio spectrogram matrix. Rows are frequency bins (0th is the lowest frequency), columns are time bins.

samples: complex
Spectrogram data.
sample_rate: int
Sample rate in samples / second of the original time domain signal.
window_size: int
Window size of the time-frequency transform used to obtain the spectrogram.
hop_size: int
Hop size of the time-frequency transform used to obtain the spectrogram.
magnitude_plot(colormap='CMRmap', min_freq=0, max_freq=None, axes=None, label_x=True, label_y=True, title=None, colorbar=True, log_mag=True)[source]

Plot the magnitude spectrogram

colormap: string
Matplotlib colormap.
min_freq: float
minimum frequency in Hz (for labelling the axis).
max_freq: float
maximum frequency in Hz (for labelling the axis).
axes: matplotlib axes object
Axes object for plotting on existing figure.
label_x: boolean
Add labels to x axis.
label_y: boolean
Add labels to y axis.
title: string
Plot title (overlaid on image).
colorbar: boolean
Add a colorbar.
log_mag: boolean
Plot log magnitude.
num_channels
num_frames

Number of spectral frames.

plot(**kwargs)[source]
class untwist.data.BinaryMask[source]

Binary Mask based on a comparison between target and background. If the threshold is 0, the mask is 1 when the target magnitude is larger than the background, and 0 otherwise.

class untwist.data.RatioMask[source]

Ratio Mask: soft mask based on ratio of target to background magnitude, with optional exponent p.

class untwist.data.Dataset(x_width, x_type, y_width=0, y_type=<type 'numpy.int64'>)[source]

In-memory Dataset

add(x, y=array([], shape=(0, 0), dtype=float64))[source]
get_batch(index, size)[source]
load(path)[source]
normalize()[source]
normalize_points(x)[source]
save(path)[source]
shuffle()[source]
standardize()[source]
standardize_points(x)[source]
class untwist.data.MMDataset(path, x_width=0, x_type=<type 'float'>, y_width=0, y_type=<type 'numpy.int64'>)[source]

Disk-based version using numpy memmap

add(x, y=None)[source]
get_batch(index, size, normalization=2)[source]
load(path)[source]
normalize_points(x)[source]
save()[source]
shuffle()[source]
standardize_points(x)[source]