Package: audalign
AudalignPackage for processing and aligning audio files using audio fingerprinting, cross-correlation, cross-correlation with spectrograms, or visual alignment techniques.This package offers tools to align many recordings of the same event. It has two main purposes: to accurately align recordings, and to process the audio files prior to alignments. All main functions are accessed through functions in the audalign.__init__ file. The recognizers themselves are objects in the recognizer directory which in turn have configurations in the config directories.Alignments are primarily accomplished with fingerprinting, though where fingerprinting fails, correlation, correlation with spectrograms, and visual alignment techniques can be used to get a closer result. After an initial alignment is found, that alignment can be passed to "fine_align," which will find smaller, relative alignments to the main one.Each alignment technique has different degrees of adjustment for accuracy settings. Fingerprinting parameters can be generally set to get consistent results using it's config'sset_accuracymethod. Visual alignment has many parameters that can be adjusted and requires case by case adjustment. Parameters for correlation are focused on sample rate or scipy's find_peaks.Noisereduceis very useful for this application and a wrapper is implemented for ease of use. Uniformly leveling prior to noise reduction using uniform_level_file boosts quiet but important sound features.Alignment and recognition results consist of a dictionary. If an output directory is given, silence is placed before all target files so that they will automatically be aligned and writen to the output directory along with an audio file containing the combined sum. Arankingskey is included in each alignment and recognition result. This helps determine the strength of the alignment, but is not definitive proof. Values range from 1-10.All formats that ffmpeg or libav support are supported here.All fingerprints are stored in memory in theFingerprintRecognzierand must be saved to disk with thesave_fingerprinted_filesmethod in order to persist them.Regular file recogniton can also be done with Audalign similar todejavu.For more details on implementation and results, see thewiki!!InstallationInstall from PyPI:Don't forget to install ffmpeg/avlib (Below in the Readme)!pipinstallaudalignORgitclonehttps://github.com/benfmiller/audalign.gitcdaudalign/
pipinstallaudalignORDownload and extract audalign thenpipinstallaudalignin the directoryRecognizersThere are currently four included recognizers, each with their own config objects.importaudalignasadfingerprint_rec=ad.FingerprintRecognizer()correlation_rec=ad.CorrelationRecognizer()cor_spec_rec=ad.CorrelationSpectrogramRecognizer()visual_rec=ad.VisualRecognizer()fingerprint_rec.config.set_accuracy(3)# recognizer.config.some_itemFor more info about the configuration objects, check out thewikior the config objects themselves. They are relatively nicely commented.Recognizers are then passed to recognize and align functions.results=ad.align("target/folder/",recognizer=fingerprint_rec)results=ad.align("target/folder/",recognizer=correlation_rec)results=ad.align("target/folder/",recognizer=cor_spec_rec)results=ad.align("target/folder/",recognizer=visual_rec)results=ad.recognize("target/file1","target/file2",recognizer=fingerprint_rec)results=ad.recognize("target/file1","target/folder",recognizer=fingerprint_rec)# orresults=ad.target_align("target/files","target/folder/",destination_path="write/alignments/to/folder",recognizer=fingerprint_rec)# orresults=ad.align_files("target/file1","target/file2",destination_path="write/alignments/to/folder",recognizer=correlation_rec)# results can then be sent to fine_alignfine_results=ad.fine_align(results,recognizer=cor_spec_rec,)Correlation is more precise than fingerprints and will always give a best alignment unlike fingerprinting, which can return no alignment.max_lagsis very important for fine aligning.localitycan be very useful for all alignments and recognitions.Other Functions# wrapper for timsainb/noisereducead.remove_noise_file("target/file","5",# noise start in seconds"20",# noise end in seconds"destination/file",alt_noise_filepath="different/sound/file",prop_decrease="0.5",# If you want noise half reduced)ad.remove_noise_directory("target/directory/","noise/file","5",# noise start in seconds"20",# noise end in seconds"destination/directory",prop_decrease="0.5",# If you want noise half reduced)ad.uniform_level_file("target/file","destination",mode="normalize",width=5,)ad.plot("file.wav")# Plots spectrogram with peaks overlaidad.convert_audio_file("audio.wav","audio.mp3")# Also convert video file to audio filead.get_metadata("file.wav")# Returns metadata from ffmpeg/ avlibYou can easily recalcute the alignment shifts from previous results using recalc_shifts.
You can then write those shifts using write_shifts_from_results. write_shifts_from_results also
lets you use different source files for alignments too.recalculated_results=ad.recalc_shifts(older_results)ad.write_shifts_from_results(recalculated_results,"destination","source_files_folder_or_file_list")FingerprintingFingerprinting is only used in the FingerprintRecognizer object. Alignments are not independent, so fingerprints created before alignments will be used for the alignment. The exception of this is in fine_aligning, where new fingerprints are always created.Running recognitions will fingerprint all files in the recognitions not already fingerprinted.fingerprint_rec=ad.FingerprintRecognizer()fingerprint_rec.fingerprint_file("test_file.wav")# orfingerprint_rec.fingerprint_directory("audio/directory")fingerprints are stored in fingerprint_rec and can be saved byfingerprint_rec.save_fingerprinted_files("save_file.json")# or .pickle# or loaded withfingerprint_rec.load_fingerprinted_files("save_file.json")# or .pickleResources and ToolsFor more tools to align audio and video files, seeforart/HyMPS's collection of alignment resources.forart/HyMPSalso has many other audio/video resources.Getting ffmpeg set upYou can useffmpeg or libav.Mac (usinghomebrew):# ffmpegbrewinstallffmpeg--with-libvorbis--with-sdl2--with-theora####    OR    ###### libavbrewinstalllibav--with-libvorbis--with-sdl--with-theoraLinux (using apt):# ffmpegapt-getinstallffmpeglibavcodec-extra####    OR    ###### libavapt-getinstalllibav-toolslibavcodec-extraWindows:Download and extract ffmpeg fromWindows binaries provided here.Add the ffmpeg/binfolder to your PATH environment variableORDownload and extract libav fromWindows binaries provided here.Add the libav/binfolder to your PATH environment variable