speechbrain.utils.superpowers 模块

应谨慎使用的超能力。

此库包含用于导入 python 文件和运行 shell 命令的函数。记住,能力越大,责任越大。

作者
  • Mirco Ravanelli 2020

  • Aku Rouhe 2021

摘要

函数

import_from_path

从绝对路径导入模块

run_shell

此函数可用于在 bash shell 中运行命令。

参考

speechbrain.utils.superpowers.import_from_path(path)[source]

从绝对路径导入模块

参数:

path (str, pathlib.Path) – 要导入模块的路径

返回:

  • module – 加载的模块

  • 实现取自

  • https (//docs.pythonlang.cn/3/library/importlib.html#importing-a-source-file-directly)

speechbrain.utils.superpowers.run_shell(cmd)[source]

此函数可用于在 bash shell 中运行命令。

参数:

cmd (str) – 要运行的 Shell 命令。

返回:

  • bytes – 捕获的标准输出。

  • bytes – 捕获的标准错误。

  • int – 返回码。

引发:

OSError – 如果返回码不是 0,即命令失败。

示例

>>> out, err, code = run_shell("echo 'hello world'")
>>> _ = out.decode(errors="ignore")