dcase_util.containers.AudioContainer

class dcase_util.containers.AudioContainer(data=None, fs=44100, focus_start_samples=None, focus_stop_samples=None, focus_channel=None, channel_labels=None, **kwargs)[source]

Audio container class.

Constructor

Parameters
datanumpy.ndarray or list of numpy.ndarray

Data to initialize the container Default value None

fsint

Target sampling frequency, if loaded audio does have different sampling frequency, audio will be re-sampled. Default value “44100”

focus_start_samplesint

Focus segment start Default value None

focus_stop_samplesint

Focus segment stop Default value None

focus_channelint

Focus segment channel Default value None

channel_labelslist

Channel names Default value None

filenamestr, optional

File path

__init__(data=None, fs=44100, focus_start_samples=None, focus_stop_samples=None, focus_channel=None, channel_labels=None, **kwargs)[source]

Constructor

Parameters
datanumpy.ndarray or list of numpy.ndarray

Data to initialize the container Default value None

fsint

Target sampling frequency, if loaded audio does have different sampling frequency, audio will be re-sampled. Default value “44100”

focus_start_samplesint

Focus segment start Default value None

focus_stop_samplesint

Focus segment stop Default value None

focus_channelint

Focus segment channel Default value None

channel_labelslist

Channel names Default value None

filenamestr, optional

File path

Methods

__init__([data, fs, focus_start_samples, ...])

Constructor

delimiter([exclude_delimiters])

Use csv.sniffer to guess delimiter for CSV file

detect_file_format([filename])

Detect file format from extension

exists()

Checks that file exists

frames([frame_length, hop_length, ...])

Slice audio into overlapping frames.

freeze()

Freeze focus segment, copy segment to be container's data.

get_file_information()

Get file information, filename

get_focused()

Get focus segment from audio data.

is_package([filename])

Determine if the file is compressed package.

load([filename, fs, mono, res_type, start, ...])

Load file

load_from_youtube(query_id[, start, stop, ...])

Load audio data from youtube

log([level])

Log container content

mixdown()

Mix all audio channels into single channel.

normalize([headroom])

Normalize audio data.

overlay(audio[, start_seconds, multiplier])

Simple sample overlay method

pad([type, length, length_seconds])

Generate signal

plot([plot_type])

Visualize audio data

plot_spec([spec_type, hop_length, cmap, ...])

Visualize audio data as spectrogram.

plot_wave([x_axis, max_points, max_sr, ...])

Visualize audio data as waveform.

resample(target_fs[, scale, res_type])

Resample audio data.

reset_focus()

Reset focus segment.

save([filename, bit_depth, bit_rate])

Save audio

segments([segment_length, ...])

Slice audio into segments.

set_focus([start, stop, duration, ...])

Set focus segment

show([mode, indent, visualize])

Print container content

to_html([indent])

Get container information in a HTML formatted string

to_string([ui, indent])

Get container information in a string

validate_format()

Validate file format

Attributes

bytes

File size in bytes

channels

Number of audio channels.

data

Audio data

duration_ms

Duration of audio data in milliseconds.

duration_samples

Duration of audio data in samples.

duration_sec

Duration of audio data in seconds.

empty

Check if audio data is empty.

focus_channel

Focus channel

focus_start_samples

Focus segment start in samples.

focus_start_seconds

Focus segment start in seconds.

focus_stop_samples

Focus segment stop in samples.

focus_stop_seconds

Focus segment stop in seconds.

length

Length of audio data in samples.

loaded

Audio load status.

logger

Logger instance

md5

Checksum for file.

shape

Audio data shape.

streams

Rename channels for compatibility.

valid_formats

Valid file formats