Skip to content

Commit

Permalink
Add simple API call (facebookresearch#474)
Browse files Browse the repository at this point in the history
* Accept simple API Call

* Fix typo
  • Loading branch information
CarlGao4 authored Apr 24, 2023
1 parent e347959 commit 14f5032
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,20 @@ If you want to use GPU acceleration, you will need at least 3GB of RAM on your G

If you do not have enough memory on your GPU, simply add `-d cpu` to the command line to use the CPU. With Demucs, processing time should be roughly equal to 1.5 times the duration of the track.

## Calling from another Python program

The main function provides a `opt` parameter as a simple API. You can just pass the parsed command line as this parameter:
```python
# Assume that your command is `demucs --mp3 --two-stems vocals -n mdx_extra "track with space.mp3"`
# The following codes are same as the command above:
import demucs.separate
demucs.separate.main(["--mp3", "--two-stems", "vocals", "-n", "mdx_extra", "track with space.mp3"])

# Or like this
import demucs.separate
import shlex
demucs.separate.main(shlex.split('--mp3 --two-stems vocals -n mdx_extra "track with space.mp3"'))
```

## Training Demucs

Expand Down
4 changes: 2 additions & 2 deletions demucs/separate.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def load_track(track, audio_channels, samplerate):
return wav


def main():
def main(opts=None):
parser = argparse.ArgumentParser("demucs.separate",
description="Separate the sources for the given tracks")
parser.add_argument("tracks", nargs='+', type=Path, default=[], help='Path to tracks')
Expand Down Expand Up @@ -115,7 +115,7 @@ def main():
help="Number of jobs. This can increase memory usage but will "
"be much faster when multiple cores are available.")

args = parser.parse_args()
args = parser.parse_args(opts)

try:
model = get_model_from_args(args)
Expand Down

0 comments on commit 14f5032

Please sign in to comment.