read_wave

ketos.data_handling.data_handling.read_wave(file, channel=0, start=0, stop=None)[source]

Read a wave file in either mono or stereo mode.

Wrapper method around

Args:
file: str

path to the wave file

channel: int

Which channel should be used in case of stereo data (0: left, 1: right)

start: int (optional)

Where to start reading. A negative value counts from the end. Defaults to 0.

stop: int (optional)

The index after the last time step to be read. A negative value counts from the end.

Returns: (rate,data)
rate: int

The sampling rate

data: numpy.array (float)

A 1d array containing the audio data

Examples:
>>> from ketos.data_handling.data_handling import read_wave
>>> rate, data = read_wave("ketos/tests/assets/2min.wav")
>>> # the function returns the sampling rate (in Hz) as an integer
>>> type(rate)
<class 'int'>
>>> rate
2000
>>> # And the actual audio data is a numpy array
>>> type(data)
<class 'numpy.ndarray'>
>>> len(data)
241664
>>> # Since each item in the vector is one sample,
>>> # The duration of the audio in seconds can be obtained by
>>> # dividing the the vector length by the sampling rate
>>> len(data)/rate
120.832