benfmiller / audalign

Package for aligning audio files through audio fingerprinting
MIT License
84 stars 2 forks source link

Higher Sample Rates issues #25

Closed pkrickeb closed 2 years ago

pkrickeb commented 2 years ago

Hi,

I have issues to align audio files with a sample rate higher than 44100 (in my case 48000).

  1 import audalign
  2 
  3 def main():
  4     ada = audalign.Audalign()
  5     rough_alignment = ada.align(
  6         "./not_aligned/",
  7         cor_sample_rate=48000,
  8         )
  9     
 10     fine_alignment = ada.fine_align(
 11         rough_alignment,
 12         destination_path="./aligned",
 13         cor_sample_rate=48000,
 14         )
 15 
 16 if __name__ == "__main__":
 17     main()

I stuck after the fingerprinting:

multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/audalign/fingerprint.py", line 109, in _fingerprint_worker
    channel, _ = audalign.filehandler.read(file_path, start_end=start_end)
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/audalign/filehandler.py", line 154, in read
    audiofile = create_audiosegment(
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/audalign/filehandler.py", line 59, in create_audiosegment
    audiofile = AudioSegment.from_file(filepath)
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/pydub/audio_segment.py", line 685, in from_file
    info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/pydub/utils.py", line 279, in mediainfo_json
    info = json.loads(output)
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "aligner.py", line 17, in <module>
    main()
  File "aligner.py", line 5, in main
    rough_alignment = ada.align(
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/audalign/__init__.py", line 22, in wrapper_decorator
    results = func(*args, **kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/audalign/__init__.py", line 1141, in align
    return align._align(
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/audalign/align.py", line 48, in _align
    set_ada_file_names(
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/audalign/align.py", line 176, in set_ada_file_names
    ada_obj.fingerprint_directory(file_dir)
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/audalign/__init__.py", line 302, in fingerprint_directory
    result = self._fingerprint_directory(
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/site-packages/audalign/__init__.py", line 388, in _fingerprint_directory
    result = self.pool.map(
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/multiprocessing/pool.py", line 364, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.8/multiprocessing/pool.py", line 771, in get
    raise self._value

Are higher sample rates supported anyway?

benfmiller commented 2 years ago

Hello,

Can you tell me what types of files you have in "./not_aligned/"? Is there a chance that any of them are corrupted? It seems as though ffmpeg is not reading the file correctly.

Different sample rates are not currently supported for fingerprinting or visrecognize through the interface. It should work just fine If you were to clone the repository and change the DEFAULT_FS value in audalign/fingerprint.py. The only area that might not work with different sample rates is noise removal. cor_sample_rate only applies to the correlation techniques.

I'm planning on restructuring the project so that alignments and recognitions will be given a recognizer class, which will separate the techniques out better. I'll also add better support for changing the sample rate.

benfmiller commented 2 years ago

I'm going to close this issue next week if there aren't any updates.