-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from carlthome/simplify-algorithms-imports
Provide example of how to add a custom segmenter implementation from outside the package
- Loading branch information
Showing
5 changed files
with
32 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import argparse | ||
|
||
import msaf | ||
|
||
import segmenter | ||
|
||
# Inject custom segmenter. | ||
setattr(msaf.algorithms, segmenter.algo_id, segmenter) | ||
msaf.algorithms.__all__.append(segmenter.algo_id) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("in_path", help="audio file") | ||
args = parser.parse_args() | ||
results = msaf.run.process(args.in_path, boundaries_id=segmenter.algo_id) | ||
print(results) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,12 @@ | ||
"""Initialisation file for all the algorithms contained in MSAF.""" | ||
import glob | ||
import importlib | ||
import os | ||
|
||
from . import interface | ||
|
||
# Get current path | ||
curr_path = os.path.dirname(os.path.realpath(__file__)) | ||
files = glob.glob(os.path.join(curr_path, "*")) | ||
|
||
# Get all modules in the current path, which should be the algorithms | ||
# available in MSAF | ||
module_names = [] | ||
for file in files: | ||
if os.path.isdir(file): | ||
if os.path.isfile(os.path.join(file, "__init__.py")): | ||
module_names.append(__name__ + "." + os.path.basename(file)) | ||
|
||
# Import all the algorithms in this folder | ||
[importlib.import_module(module_name) for module_name in module_names] | ||
|
||
# Also init the __all__ var in case they want to use "*" to import all | ||
__all__ = [module_name.split(".")[-1] for module_name in module_names] | ||
|
||
# Clean up variable space | ||
del curr_path | ||
del files | ||
del module_names | ||
del os | ||
del glob | ||
del file | ||
from . import cnmf, fmc2d, foote, olda, scluster, sf, vmo | ||
|
||
__all__ = [ | ||
"cnmf", | ||
"fmc2d", | ||
"foote", | ||
"olda", | ||
"scluster", | ||
"sf", | ||
"vmo", | ||
] |