Skip to content

Commit

Permalink
flac output & max_allowed_segment only for HTDemucs (facebookresearch…
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlGao4 authored May 24, 2023
1 parent 8339657 commit 75bbaa5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test_eval:
python3 -m demucs -n demucs_unittest test.mp3
python3 -m demucs -n demucs_unittest --two-stems=vocals test.mp3
python3 -m demucs -n demucs_unittest --mp3 test.mp3
python3 -m demucs -n demucs_unittest --flac --int24 test.mp3
python3 -m demucs -n demucs_unittest --int24 --clip-mode clamp test.mp3
python3 -m demucs -n demucs_unittest --segment 8 test.mp3

Expand Down
3 changes: 2 additions & 1 deletion demucs/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def __init__(self, models: tp.List[Model],
def max_allowed_segment(self) -> float:
max_allowed_segment = float('inf')
for model in self.models:
max_allowed_segment = min(max_allowed_segment, float(model.segment))
if isinstance(model, HTDemucs):
max_allowed_segment = min(max_allowed_segment, float(model.segment))
return max_allowed_segment

def forward(self, x):
Expand Down
2 changes: 2 additions & 0 deletions demucs/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,7 @@ def save_audio(wav: torch.Tensor,
encoding = 'PCM_S'
ta.save(str(path), wav, sample_rate=samplerate,
encoding=encoding, bits_per_sample=bits_per_sample)
elif suffix == ".flac":
ta.save(str(path), wav, sample_rate=samplerate, bits_per_sample=bits_per_sample)
else:
raise ValueError(f"Invalid suffix for path: {suffix}")
11 changes: 8 additions & 3 deletions demucs/separate.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ def get_parser():
parser.add_argument("--clip-mode", default="rescale", choices=["rescale", "clamp"],
help="Strategy for avoiding clipping: rescaling entire signal "
"if necessary (rescale) or hard clipping (clamp).")
parser.add_argument("--mp3", action="store_true",
help="Convert the output wavs to mp3.")
format_group = parser.add_mutually_exclusive_group()
format_group.add_argument("--flac", action="store_true",
help="Convert the output wavs to flac.")
format_group.add_argument("--mp3", action="store_true",
help="Convert the output wavs to mp3.")
parser.add_argument("--mp3-bitrate",
default=320,
type=int,
Expand All @@ -128,7 +131,7 @@ def main(opts=None):
except ModelLoadingError as error:
fatal(error.args[0])

max_allowed_segment: float = float('inf')
max_allowed_segment = float('inf')
if isinstance(model, HTDemucs):
max_allowed_segment = float(model.segment)
elif isinstance(model, BagOfModels):
Expand Down Expand Up @@ -170,6 +173,8 @@ def main(opts=None):

if args.mp3:
ext = "mp3"
elif args.flac:
ext = "flac"
else:
ext = "wav"
kwargs = {
Expand Down
4 changes: 4 additions & 0 deletions docs/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

## V4.0.1a1, TBD

**From this version, Python 3.7 is no longer supported. This is not a problem since the latest PyTorch 2.0.0 no longer support it either.**

Various improvements by @CarlGao4. Support for `segment` param inside of HTDemucs
model.

Made diffq an optional dependency, with an error message if not installed.

Added output format flac (Free Lossless Audio Codec)

## V4.0.0, 7th of December 2022

Adding hybrid transformer Demucs model.
Expand Down

0 comments on commit 75bbaa5

Please sign in to comment.