Skip to content

Factory

TranscriberFactoryABC

Bases: ABC

Source code in asrbench\transcribers\abc_factory.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
class TranscriberFactoryABC(ABC):

    @abstractmethod
    def get_transcriber(self, name: str, cfg: Dict[str, Any]) -> Transcriber:
        """Get Transcriber with config"""
        raise NotImplementedError("Implement get_transcriber method.")

    @abstractmethod
    def from_config(
            self,
            config: Dict[str, Dict[str, Any]],
    ) -> Dict[str, Transcriber]:
        """Set up transcribers dict from transcribers section in config file"""
        raise NotImplementedError("Implement from_config method.")

from_config(config) abstractmethod

Set up transcribers dict from transcribers section in config file

Source code in asrbench\transcribers\abc_factory.py
13
14
15
16
17
18
19
@abstractmethod
def from_config(
        self,
        config: Dict[str, Dict[str, Any]],
) -> Dict[str, Transcriber]:
    """Set up transcribers dict from transcribers section in config file"""
    raise NotImplementedError("Implement from_config method.")

get_transcriber(name, cfg) abstractmethod

Get Transcriber with config

Source code in asrbench\transcribers\abc_factory.py
 8
 9
10
11
@abstractmethod
def get_transcriber(self, name: str, cfg: Dict[str, Any]) -> Transcriber:
    """Get Transcriber with config"""
    raise NotImplementedError("Implement get_transcriber method.")

DefaultTranscriberFactory

Bases: TranscriberFactoryABC

Source code in asrbench\transcribers\factory.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class DefaultTranscriberFactory(TranscriberFactoryABC):
    def __init__(self) -> None:
        self.__registry: TranscriberRegistry = TranscriberRegistry()

    def get_transcriber(self, name: str, cfg: Dict[str, Any]) -> Transcriber:
        """Return TranscriberABC with config"""
        if "asr" not in cfg:
            raise KeyError(f"Missing asr in {name} config.")

        transcriber = self.__registry.get_transcriber(cfg["asr"])
        return transcriber.from_config(name, cfg)

    def from_config(
            self,
            config: Dict[str, Dict[str, Any]],
    ) -> Dict[str, Transcriber]:
        """Set up transcribers dict from transcribers section in config file.

        Arguments:
           config: transcribers section of the configuration file.
        """
        transcribers: Dict[str, Transcriber] = {}

        for name, transcriber_cfg in config.items():
            transcribers[name] = self.get_transcriber(name, transcriber_cfg)

        logging.debug(f"transcribers for benchmark: {transcribers.__str__()}")
        return transcribers

from_config(config)

Set up transcribers dict from transcribers section in config file.

Parameters:

Name Type Description Default
config Dict[str, Dict[str, Any]]

transcribers section of the configuration file.

required
Source code in asrbench\transcribers\factory.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def from_config(
        self,
        config: Dict[str, Dict[str, Any]],
) -> Dict[str, Transcriber]:
    """Set up transcribers dict from transcribers section in config file.

    Arguments:
       config: transcribers section of the configuration file.
    """
    transcribers: Dict[str, Transcriber] = {}

    for name, transcriber_cfg in config.items():
        transcribers[name] = self.get_transcriber(name, transcriber_cfg)

    logging.debug(f"transcribers for benchmark: {transcribers.__str__()}")
    return transcribers

get_transcriber(name, cfg)

Return TranscriberABC with config

Source code in asrbench\transcribers\factory.py
14
15
16
17
18
19
20
def get_transcriber(self, name: str, cfg: Dict[str, Any]) -> Transcriber:
    """Return TranscriberABC with config"""
    if "asr" not in cfg:
        raise KeyError(f"Missing asr in {name} config.")

    transcriber = self.__registry.get_transcriber(cfg["asr"])
    return transcriber.from_config(name, cfg)