Install pychorus via pip
masterInstall the pychorus library using the standard Python package manager.
pip install pychorusrepository·master·Indexed 42 days ago
https://github.com/vivjay30/pychorusAn open source Python library for detecting choruses and repeating sections in musical audio files using chromagram-based similarity matrices. It provides a CLI and a Python API, including the `find_and_output_chorus` function and tools for generating and visualizing Time-Time and Time-Lag similarity matrices.
Install the pychorus library using the standard Python package manager.
pip install pychorusFor deeper analysis, you can manually generate chromagrams and similarity matrices (Time-Time and Time-Lag) to visualize how different sections of the music relate to each other.
create_chroma to generate the chromagram and sample rate.TimeTimeSimilarityMatrix and TimeLagSimilarityMatrix with the chroma and sample rate..display() on the matrix objects to visualize the results.from pychorus import create_chroma
from pychorus.similarity_matrix import TimeTimeSimilarityMatrix, TimeLagSimilarityMatrix
# Generate chromagram
chroma, _, sr, _ = create_chroma("path/to/audio_file")
# Create matrices
time_time_similarity = TimeTimeSimilarityMatrix(chroma, sr)
time_lag_similarity = TimeLagSimilarityMatrix(chroma, sr)
# Visualize the results
time_time_similarity.display()
time_lag_similarity.display()The simplest way to detect a chorus is to use the find_and_output_chorus function. This function identifies a chorus section in an audio file and saves it to a specified output file. It returns the starting time of the chorus in seconds.
from pychorus import find_and_output_chorus
# clip_length is the duration of the section to be extracted
chorus_start_sec = find_and_output_chorus("path/to/audio_file", "path/to/output_file", clip_length)If you have cloned the repository, you can run the detection process directly from the terminal using main.py.
python main.py path/to/audio_file --output_file=path/to/output_fileThe pychorus CLI allows you to identify the chorus of a music file and save it to a new audio file. It accepts a required input file path and provides optional flags to specify the output destination and the minimum duration required for a segment to be classified as a chorus.
Arguments:
input_file: Path to the source audio file.Options:
--output_file: The path where the detected chorus will be saved. Defaults to chorus.wav.--min_clip_length: The minimum length in seconds for a segment to be considered a chorus. Defaults to 15 seconds.# Basic usage (outputs to chorus.wav)
python main.py input.wav
# Specify custom output and minimum clip length
python main.py input.wav --output_file my_chorus.wav --min_clip_length 20