pyscab package#

Submodules#

pyscab.DataHandler module#

class pyscab.DataHandler.DataHandler(frame_rate=44100, verbose=False)[source]#

Bases: object

Handling 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_nframes_by_id(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: object

class 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.

init()[source]#

initialize all parameters hold by CallbackParams instance.

class pyscab.HardwareController.HardwareInformation(pya)[source]#

Bases: object

get 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.

get_output_device_with_name(device_name)[source]#

get device information by name.

Parameters
device_namestr

name of the device.

Returns
devicepyaudio.PaDeviceInfo
class pyscab.HardwareController.ReadAudioChunk(data, chunk_size, ch, volume=1.0, format=dtype('int16'), idx_obj=None)[source]#

Bases: object

reading 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.

is_finished()

check if it's finished

read_chunk()

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.

is_finished()[source]#

check if it’s finished

Returns
is_finishedbool

True if all data already been read, False if there’s remained data.

read_chunk()[source]#

read audio data by chunk.

Returns
chunk_datanumpy.ndarray

chunk data which have a shape of (chunk size, number of channels)

pyscab.HardwareController.callback(in_data, frame_count, time_info, status, p=<pyscab.HardwareController.CallbackParams object>)[source]#
pyscab.HardwareController.get_available_devices()[source]#

print available devices connected to the computer.

pyscab.StimulationController module#

class pyscab.StimulationController.StimulationController(AudioHardwareController, marker_send, time_tick=0.0001)[source]#

Bases: object

Methods

play

play(plans, data, time_termination='auto', pause=0.5)[source]#
pyscab.StimulationController.get_required_time(plans, data)[source]#

pyscab.utils module#

pyscab.utils.generate_pcm(number_of_channels=1, frequency=440, duration=1.0, volume=1.0, fs=44100, format='INT16', window='linear', t_raise_fall=0.01)[source]#

Module contents#