Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError when calling signal.windows() with preprocess=False #94

Open
hugofloresgarcia opened this issue Aug 14, 2023 · 1 comment

Comments

@hugofloresgarcia
Copy link
Contributor

hugofloresgarcia commented Aug 14, 2023

Traceback (most recent call last):
  File "/home/hugo/descript/vampnet-v0/scripts/utils/split_long_audio_file.py", line 31, in <module>
    split_long_audio_file()
  File "/home/hugo/miniconda3/envs/vampnet/lib/python3.9/site-packages/argbind/argbind.py", line 159, in cmd_func
    return func(*cmd_args, **kwargs)
  File "/home/hugo/descript/vampnet-v0/scripts/utils/split_long_audio_file.py", line 20, in split_long_audio_file
    for sig in tqdm.tqdm(sig.windows(window_duration=max_chunk_size_s, hop_duration=max_chunk_size_s/2, preprocess=False)):
  File "/home/hugo/miniconda3/envs/vampnet/lib/python3.9/site-packages/tqdm/std.py", line 1182, in __iter__
    for obj in iterable:
  File "/home/hugo/miniconda3/envs/vampnet/lib/python3.9/site-packages/audiotools/core/dsp.py", line 61, in windows
    start_idx = i * hop_length
UnboundLocalError: local variable 'hop_length' referenced before assignment

here's a script to repro:

from pathlib import Path
import argbind

import audiotools as at
import tqdm


@argbind.bind(without_prefix=True)
def split_long_audio_file(
    file: str = None, 
    max_chunk_size_s: int = 60*10
):
    file = Path(file)
    output_dir = file.parent / file.stem
    output_dir.mkdir()
    
    sig = at.AudioSignal(file)

    # split into chunks
    for i, sig in tqdm.tqdm(enumerate(sig.windows(
        window_duration=max_chunk_size_s, hop_duration=max_chunk_size_s/2, 
        preprocess=True))
    ):
        sig.write(output_dir / f"{i}.wav")

    print(f"wrote {len(list(output_dir.glob('*.wav')))} files to {output_dir}")
    
    return output_dir

if __name__ == "__main__":
    args = argbind.parse_args()

    with argbind.scope(args):
        split_long_audio_file()
@v-i-s-h
Copy link

v-i-s-h commented Oct 3, 2023

+1
Related to #76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants