pychorus

repository·master·Indexed 42 days ago

https://github.com/vivjay30/pychorus

An 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.

Tokens
842
Snippets
5
Records
5
Agent score
3%

What's inside pychorus

  1. Generate and visualize similarity matrices

    master

    For 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.

    1. Use create_chroma to generate the chromagram and sample rate.
    2. Initialize TimeTimeSimilarityMatrix and TimeLagSimilarityMatrix with the chroma and sample rate.
    3. Call .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()
  2. Find and output a chorus using find_and_output_chorus

    master

    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)
  3. Use the pychorus CLI to find and output a chorus

    master

    The 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