faunanet_record package

Submodules

faunanet_record.audio_recording module

class faunanet_record.audio_recording.Recorder(output_folder=None, length_s=15, sample_rate=32000, channels=1, mode='record', input_device_index=None, chunk_size=1000)

Bases: RecorderBase

Recorder Implementation of RecorderBase that uses PyAudio to record data.

Methods:

start(stop_condition = lambda x: False): Make the caller start generate data. Runs until ‘stop_condition(self)’ returns True. stream_audio(): Get a chunk of recorded data corresponding to ‘length_in_s’ seconds of recording. stop(): Stop recorder and release held resources of PyAudio. from_cfg(cfg) (classmethod): Build a new instance of this class from a dictionary, usually obtained by reading a yaml config is_running(): check if the pyaudio stream held by the caller is still active.

classmethod from_cfg(cfg)

from_cfg Creates a new Recorder instance. All arguments not given in the cfg argument are filled with default values of the constructor.

Parameters:

cfg (dict) – Dictionary, obtained from reading a yaml config file, that contains the keyword arguments to construct the Recorder from.

Raises:

ValueError – When the supplied dictionary does not have an ‘output_folder’ node.

Returns:

A new instance of the Recorder class, built with the supplied arguments.

Return type:

Recorder

property is_running

is_running Checks if the recording is running or not.

Returns:

Flag that tells if the recording is running or not

Return type:

Bool

start(stop_condition=<function Recorder.<lambda>>)

start Start the pyaudio input stream such that data is gathered. If self.mode is ‘record’, write wave files of ‘self.length_in_s’ seconds length to disk into ‘self.output_folder’.

Parameters:

stop_condition (_type_, optional) – Only relevant for self.mode = ‘record’. Callable that returns True when the recording process should be stopped. Is checked each time a file is written, i.e., every ‘self.length_in_s’ seconds of recording. Defaults to lambda x:False.

Raises:

e – Generic exception if an error occurs during recording data or writing to file.

stop()

stop Stop the recording process, but keep resources around to restart later if desired.

stream_audio()

stream_audio Get a chunk of recorded data that corresponds to ‘self.length_in_s’ seconds of audio.

Returns:

Tuple containing the number of bytes in the recorded chunk, and the recorded data as raw bytes buffer.

Return type:

Tuple[int, bytes]

Parameters:
  • output_folder (str)

  • length_s (int)

  • sample_rate (int)

  • channels (int)

  • mode (str)

  • input_device_index (int)

  • chunk_size (int)

class faunanet_record.audio_recording.RecorderBase(output_folder=None, length_s=15, sample_rate=32000, file_type='wave', channels=1, mode='record', num_format=None)

Bases: ABC

RecorderBase Abstract base class for any audio recording functionality that shall be used with faunanet.

Methods:

start(stop_condition = lambda x: False): Abstract method that needs to be implemented by derived class. Should make the caller start generate data. Runs until ‘stop_condition(self)’ returns True. stream_audio(): Abstract method that needs to be implemented by derived class. Should get a chunk of recorded data corresponding to ‘length_in_s’ seconds of recording. stop(): Abstract method that needs to be implemented by derived class. Should stop the recorder’s data collecting process and release resources.

property output
abstract start(stop_condition=<function RecorderBase.<lambda>>)
Parameters:

stop_condition (callable)

abstract stop()
abstract stream_audio()
Parameters:
  • output_folder (str)

  • length_s (int)

  • sample_rate (int)

  • file_type (str)

  • channels (int)

  • mode (str)

  • num_format (int)

faunanet_record.cli module

faunanet_record.runner module

class faunanet_record.runner.Runner(custom_config=None, config_folder='/home/docs/.config/faunanet_record')

Bases: object

Class that runs data collection.

Attributes:

config (dict): Configuration parameters for data collection end_time (int or datetime): Limit for how long or until when to collect data recorder (iSparroRecord.Recorder): Recorder to collect data. See faunanet.RecorderBase documentation

Methods:

output Get the output data folder run Run data collection

run()

run Collect data until a certain datetime has been reached, or for a certain amount of seconds or indefinitely.

Parameters:
  • custom_config (dict)

  • config_folder (str)

faunanet_record.set_up module

faunanet_record.set_up.make_directories(base_cfg_dirs)

make_directories Make all the directories needed for faunanet_record.

Parameters:
  • base_cfg_dirs (dict) – Dictionary containing paths for the main install (“home”),

  • stored (the directory where models are)

  • in (and the "output" directory to store inference results and potentially other data)

Raises:

KeyError – A folder given in the config does not exist

Returns:

created folders: ( datafolder, configfolder)

Return type:

tuple

faunanet_record.set_up.set_up(cfg_path='')

set_up set up the faunanet-record system to be ready for running and recording data. Makes data and config folders and copies the default configs there.

Parameters:
  • cfg_path (str) – Path to a folder containing “default.yml” (the default parameters) and “install.yml” (the install parameters).

  • for_tests (bool, optional) – Whether a special ‘test’ directory should be created for testing. Used in unit tests to not interfer with base installation mostly. Defaults to False.

faunanet_record.utils module

faunanet_record.utils.dict_from_string(dict_repr)
Parameters:

dict_repr (str)

faunanet_record.utils.read_yaml(path)
read_yaml Read the yaml basic config file for faunanet from path.

It contains the install directory, data directory and other things used by faunanet internally.

Parameters:

path (str) – Path to the yaml base config.

Returns:

read base config file.

Return type:

dict

faunanet_record.utils.update_dict_recursive(base, update)

_update_dict_recursive Merge recursively two arbitrarily nested dictionaries such that only those leaves of ‘base’ are upated with the content of ‘update’ for which the given path in ‘update’ fully exists in ‘base’.

This function assumes that nodes in ‘base’ are only replaced, and ‘update’ does not add new nodes.

Parameters:
  • base (dict) – Base dictionary to update.

  • update (dict) – dictionary to update ‘base’ with.

Module contents

class faunanet_record.Recorder(output_folder=None, length_s=15, sample_rate=32000, channels=1, mode='record', input_device_index=None, chunk_size=1000)

Bases: RecorderBase

Recorder Implementation of RecorderBase that uses PyAudio to record data.

Methods:

start(stop_condition = lambda x: False): Make the caller start generate data. Runs until ‘stop_condition(self)’ returns True. stream_audio(): Get a chunk of recorded data corresponding to ‘length_in_s’ seconds of recording. stop(): Stop recorder and release held resources of PyAudio. from_cfg(cfg) (classmethod): Build a new instance of this class from a dictionary, usually obtained by reading a yaml config is_running(): check if the pyaudio stream held by the caller is still active.

classmethod from_cfg(cfg)

from_cfg Creates a new Recorder instance. All arguments not given in the cfg argument are filled with default values of the constructor.

Parameters:

cfg (dict) – Dictionary, obtained from reading a yaml config file, that contains the keyword arguments to construct the Recorder from.

Raises:

ValueError – When the supplied dictionary does not have an ‘output_folder’ node.

Returns:

A new instance of the Recorder class, built with the supplied arguments.

Return type:

Recorder

property is_running

is_running Checks if the recording is running or not.

Returns:

Flag that tells if the recording is running or not

Return type:

Bool

start(stop_condition=<function Recorder.<lambda>>)

start Start the pyaudio input stream such that data is gathered. If self.mode is ‘record’, write wave files of ‘self.length_in_s’ seconds length to disk into ‘self.output_folder’.

Parameters:

stop_condition (_type_, optional) – Only relevant for self.mode = ‘record’. Callable that returns True when the recording process should be stopped. Is checked each time a file is written, i.e., every ‘self.length_in_s’ seconds of recording. Defaults to lambda x:False.

Raises:

e – Generic exception if an error occurs during recording data or writing to file.

stop()

stop Stop the recording process, but keep resources around to restart later if desired.

stream_audio()

stream_audio Get a chunk of recorded data that corresponds to ‘self.length_in_s’ seconds of audio.

Returns:

Tuple containing the number of bytes in the recorded chunk, and the recorded data as raw bytes buffer.

Return type:

Tuple[int, bytes]

Parameters:
  • output_folder (str)

  • length_s (int)

  • sample_rate (int)

  • channels (int)

  • mode (str)

  • input_device_index (int)

  • chunk_size (int)

class faunanet_record.Runner(custom_config=None, config_folder='/home/docs/.config/faunanet_record')

Bases: object

Class that runs data collection.

Attributes:

config (dict): Configuration parameters for data collection end_time (int or datetime): Limit for how long or until when to collect data recorder (iSparroRecord.Recorder): Recorder to collect data. See faunanet.RecorderBase documentation

Methods:

output Get the output data folder run Run data collection

run()

run Collect data until a certain datetime has been reached, or for a certain amount of seconds or indefinitely.

Parameters:
  • custom_config (dict)

  • config_folder (str)