Class DataHandler#
- class pyscab.DataHandler.DataHandler(frame_rate=44100, verbose=False)[source]#
Bases:
objectHandling wav files and pcm data.
- Parameters
- frame_rateint, default=44100
frame rate of data.
- verbosebool, default=False
verbosity while data loading.
- Attributes
- pcm_datalist
loaded audio data.
- n_chlist of int
number of channels of loaded audio data.
- n_frameslist of int
number of frames of loaded audio data.
- pathslist of str
path of loaded audio file.
- idlist of int
id of loaded audio data.
- volumelist of float
volume of loaded audio data.
- frame_rateint
frame rate of data
- sample widthlist of int
sample width in byte of loaded audio data.
- dtypenumpy.dtype
data format type.
Methods
add_pcm(id, data)Add the pcm audio data (matrix) to DataHandler.
apply_window(id, t_raise_fall)Applying window function to data specified by id.
get_data_by_id(id)get data of the audio data specified by id.
get_length_by_id(id)get length (in seconds) of the audio data specified by id.
get_n_ch_by_id(id)get number of channels of the audio data specified by id.
get number of frames of the audio data specified by id.
get_path_by_id(id)get file path of the audio data specified by id.
load(id, path[, volume])Load wav file by path.
- add_pcm(id, data)[source]#
Add the pcm audio data (matrix) to DataHandler.
- Parameters
- idint
id for this audio data.
- datanumpy.ndarray
audio data. shoule have shape of (number of samples, number of channels)
- Raises
- ValueError
Raises ValueError if existing (already been used) id is passed to id.
Notes
File path will be automatically set to “PCM”
- apply_window(id, t_raise_fall)[source]#
Applying window function to data specified by id.
- Parameters
- idint
data id to be applied filter function.
- t_raise_fallfloat
time duration for raise and fall.
Notes
If r_raise_fall is set to 0.05. Both raising and falling time will be set to 0.05. Currently, only linear function can be applied. Other function will be implemented in the future.
- get_data_by_id(id)[source]#
get data of the audio data specified by id.
- Parameters
- idint
id of audio data.
- Returns
- datanumpy.ndarray
audio data array specified by id.
- get_length_by_id(id)[source]#
get length (in seconds) of the audio data specified by id.
- Parameters
- idint
id of audio data.
- Returns
- lengthint
length (in seconds) of the audio data specified by id.
- get_n_ch_by_id(id)[source]#
get number of channels of the audio data specified by id.
- Parameters
- idint
id of audio data.
- Returns
- number_of_channelsint
number of channels of audio data specified by id.
- get_nframes_by_id(id)[source]#
get number of frames of the audio data specified by id.
- Parameters
- idint
id of audio data.
- Returns
- number_of_framesint
number of frames of the audio data specified by id.
- get_path_by_id(id)[source]#
get file path of the audio data specified by id.
- Parameters
- idint
id of audio data.
- Returns
- pathstr
file path of audio data specified by id.
- load(id, path, volume=1.0)[source]#
Load wav file by path.
- Parameters
- idint
id for this audio data.
- pathstr
file path of audio file to be loaded.
- volumefloat, default=1.0
volume for this audio data.
- Raises
- ValueError
Raises ValueError if existing (already been used) id is passed to id.
- ValueError
Raises ValueError if format of loaded wav file is not Int16 or UInt8.
Examples
You just need to specify the id for data, and file path to be loaded.
>>> import pyscab >>> dh = pyscab.DataHandler() >>> dh.load(1, path = "/home/USER/Music/something.wav", volume = 0.5)