pydrobert.kaldi.logging

Tie Kaldi’s logging into python’s builtin logging module

By default, Kaldi’s warning, error, and critical messages are all piped directly to stderr. Any logging.Logger instance can register with register_logger_for_kaldi to receive Kaldi messages. If some logger is registered to receive Kaldi messages, messages will no longer be sent to stderr by default. Kaldi codes are converted to logging codes according to the following chart

logging

kaldi

CRITICAL(50+)

-3+

ERROR(40-49)

-2

WARNING(30-39)

-1

INFO(20-29)

0

DEBUG(10-19)

1

9 down to 1

2 up to 10

class pydrobert.kaldi.logging.KaldiLogger(name, level=0)[source]

Bases: Logger

Logger subclass that overwrites log info with kaldi’s

Setting the Logger class of the python module logging (thru logging.setLoggerClass) to KaldiLogger will allow new loggers to intercept messages from Kaldi and inject Kaldi’s trace information into the record. With this injection, the logger will point to the location in Kaldi’s source that the message originated from. Without it, the logger will point to a location within this submodule (pydrobert.kaldi.logging).

makeRecord(name, lvl, fn, lno, msg, args, exc_info, func=None, extra=None, sinfo=None)[source]

Instances of the Logger class represent a single logging channel. A “logging channel” indicates an area of an application. Exactly how an “area” is defined is up to the application developer. Since an application can have any number of areas, logging channels are identified by a unique string. Application areas can be nested (e.g. an area of “input processing” might include sub-areas “read CSV files”, “read XLS files” and “read Gnumeric files”). To cater for this natural nesting, channel names are organized into a namespace hierarchy where levels are separated by periods, much like the Java or Python package namespace. So in the instance given above, channel names might be “input” for the upper level, and “input.csv”, “input.xls” and “input.gnu” for the sub-levels. There is no arbitrary limit to the depth of nesting.

pydrobert.kaldi.logging.deregister_logger_for_kaldi(name)[source]

Deregister logger previously registered w register_logger_for_kaldi

pydrobert.kaldi.logging.kaldi_lvl_to_logging_lvl(lvl)[source]

Convert kaldi level to logging level

pydrobert.kaldi.logging.kaldi_vlog_level_cmd_decorator(func)[source]

Decorator to rename, then revert, level names according to Kaldi 1

See pydrobert.kaldi.logging for the conversion chart. After the return of the function, the level names before the call are reverted. This function is insensitive to renaming while the function executes

References

1

Povey, D., et al (2011). The Kaldi Speech Recognition Toolkit. ASRU

pydrobert.kaldi.logging.logging_lvl_to_kaldi_lvl(lvl)[source]

Convert logging level to kaldi level

pydrobert.kaldi.logging.register_logger_for_kaldi(logger)[source]

Register logger to receive Kaldi’s messages

See module docstring for more info

Parameters

logger (str or logger) – Either the logger or its name. When a new message comes along from Kaldi, the callback will send a message to the logger