paddlespeech.cli.executor module

class paddlespeech.cli.executor.BaseExecutor(task: str, **kwargs)[source]

Bases: ABC

An abstract executor of paddlespeech tasks.

Methods

__call__(*arg, **kwargs)

Python API to call an executor.

disable_task_loggers()

Disable all loggers in current task.

execute(argv)

Command line entry.

get_input_source(input_)

Get task input source from command line input.

infer(*args, **kwargs)

Model inference and put results into self._outputs.

postprocess(*args, **kwargs)

Output postprocess and return results.

preprocess(input, *args, **kwargs)

Input preprocess and return paddle.Tensor stored in self._inputs.

process_task_results(input_, results[, ...])

Handling task results and redirect stdout if needed.

show_rtf(info)

Calculate rft of current task and show results.

disable_task_loggers()[source]

Disable all loggers in current task.

abstract execute(argv: List[str]) bool[source]

Command line entry. This method can only be accessed by a command line such as paddlespeech asr.

Args:

argv (List[str]): Arguments from command line.

Returns:

int: Result of the command execution. True for a success and False for a failure.

get_input_source(input_: Optional[Union[str, PathLike]]) Dict[str, Union[str, PathLike]][source]

Get task input source from command line input.

Args:

input_ (Union[str, os.PathLike, None]): Input from command line.

Returns:

Dict[str, Union[str, os.PathLike]]: A dict with ids and inputs.

abstract infer(*args, **kwargs)[source]

Model inference and put results into self._outputs. This method get input tensors from self._inputs, and write output tensors into self._outputs.

abstract postprocess(*args, **kwargs) Union[str, PathLike][source]

Output postprocess and return results. This method get model output from self._outputs and convert it into human-readable results.

Returns:

Union[str, os.PathLike]: Human-readable results such as texts and audio files.

abstract preprocess(input: Any, *args, **kwargs)[source]

Input preprocess and return paddle.Tensor stored in self._inputs. Input content can be a text(tts), a file(asr, cls), a stream(not supported yet) or anything needed.

Args:

input (Any): Input text/file/stream or other content.

process_task_results(input_: Optional[Union[str, PathLike]], results: Dict[str, PathLike], job_dump_result: bool = False)[source]

Handling task results and redirect stdout if needed.

Args:

input_ (Union[str, os.PathLike, None]): Input from command line. results (Dict[str, os.PathLike]): Task outputs. job_dump_result (bool, optional): if True, dumps job results into file. Defaults to False.

show_rtf(info: Dict[str, List[float]])[source]

Calculate rft of current task and show results.