pyscab package#
Submodules#
pyscab.DataHandler module#
- 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)
pyscab.HardwareController module#
- class pyscab.HardwareController.CallbackParams[source]#
Bases:
objectclass for referencing parameters of callback function of portaudio.
- Attributes
- datalist of pyscab.ReadAudioChunk
containing audio data to play.
- data_finishedlist of bool
True if all audio data in attribute data which has corresponding index were played.
Methods
init()initialize all parameters hold by CallbackParams instance.
- class pyscab.HardwareController.HardwareInformation(pya)[source]#
Bases:
objectget hardware information of audio devices.
- Attributes
- devicesdict
containes device name and maximum number of output channels of each device. keys : ‘name’, ‘maxOutputChannels’
Methods
get_output_device_with_name(device_name)get device information by name.
- class pyscab.HardwareController.ReadAudioChunk(data, chunk_size, ch, volume=1.0, format=dtype('int16'), idx_obj=None)[source]#
Bases:
objectreading audio data by chunk.
- Attributes
- datanumpy.ndarray
audio data.
- n_ch_dataint
number of channels of audio data
- n_framesint
number of frames of audio data
- chunk_sixeint
chunk size.
- chlist of int
channel number of device which audio data will be played.
- formatnumpy.dtype
audio data format
- finishedBool
If True, all audio data have already been read. If False, there’s remained data.
- idx_objint
id of instance.
Methods
get_ch()get channel number to play the audio data.
check if it's finished
read audio data by chunk.
- get_ch()[source]#
get channel number to play the audio data.
- Returns
- channellist of int
channel number which audio data will be played.