### Install Dependencies Source: https://github.com/andreamust/chordsync/blob/main/README.md Install the required Python packages from the requirements file. ```bash pip install -r requirements.txt ``` -------------------------------- ### Load Audio and Get Duration Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Loads an audio file using librosa and calculates its duration. ```python import librosa # type: ignore # load the audio file y, sr = librosa.load(audio_file, sr=None) # get the duration of the audio file duration = librosa.get_duration(y=y, sr=sr) duration, sr ``` -------------------------------- ### Get Audio IDs Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Retrieves associated audio IDs for a given score file stem. ```python # get all audios for the example score file audio_ids = get_audio_ids(score_file.stem, "./data/schubert-winterreise/") audio_ids ``` -------------------------------- ### Define and Verify Paths Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Sets up paths for audio and score data and verifies their existence. ```python # define paths audio_path = Path("/media/data/andrea/choco_audio/audio") score_path = Path("./data/schubert-winterreise/csv-score") jams_score_path = Path("./data/schubert-winterreise/jams-score") jams_audio_path = Path("/media/data/andrea/choco_audio/jams") audio_path.exists(), score_path.exists() ``` -------------------------------- ### Pre-process Data Source: https://github.com/andreamust/chordsync/blob/main/README.md Prepare audio and JAMS annotation files for training by generating a cache. ```bash python ChordSync/data/data_preprocessing.py --audio_folder path/to/audio/folder --jams_folder path/to/jams/folder -max_sequence_length 15 --excerpt_per_song 25 --excerpt_distance 12 --cache_name cache --device cpu --num_workers 4 ``` -------------------------------- ### Run Synchronization Source: https://github.com/andreamust/chordsync/blob/main/README.md Perform chord synchronization on a new audio file using a pre-trained model checkpoint. ```bash python ChordSync/sync.py --audio_file path/to/audio/file --model_path models/chordsync_v.0.1.0.ckpt --output_folder path/to/output/folder --device cpu ``` -------------------------------- ### Initialize and process audio-score alignment Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Creates an AudioScoreAlignment instance and computes the alignment with visualization enabled. ```python for audio_id in audio_ids[:1]: print(audio_id) # create the audio score alignment object alignment = AudioScoreAlignment( audio_path=audio_file, score_path=score_file, feature_rate=FEATURE_RATE ) alignment = alignment.get_alignment(visualize=True) alignment ``` -------------------------------- ### Create Conda Environment Source: https://github.com/andreamust/chordsync/blob/main/README.md Initialize a new Conda environment with Python 3.11 for the project. ```bash conda create -n chordsync python=3.11 conda activate chordsync ``` -------------------------------- ### Train Model Source: https://github.com/andreamust/chordsync/blob/main/README.md Execute the training process using PyTorch Lightning with default parameters. ```bash python ChordSync/train.py ``` -------------------------------- ### Retrieve audio onsets Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Fetches the ground truth audio onsets for a specific file. ```python # get the corresponding audio onsets audio_onsets = get_audio_jams_onsets(audio_file.stem, jams_audio_path) len(audio_onsets) ``` -------------------------------- ### Configure System Path Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Adds the parent directory to the system path to enable module imports. ```python import sys sys.path.append("../") ``` -------------------------------- ### Construct Audio File Path Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Constructs the full path for a specific audio file based on its ID. ```python audio_stem = audio_ids[3] audio_file = audio_path / f"{audio_stem}.flac" audio_file ``` -------------------------------- ### Importing Libraries Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/hcdf/compute_results.ipynb Initial imports required for data manipulation and file path handling. ```python import pandas as pd from pathlib import Path ``` -------------------------------- ### Import Dependencies Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Imports necessary libraries and utility functions for audio-score alignment. ```python from pathlib import Path import numpy as np # type: ignore from audio_score_alignment import AudioScoreAlignment from dtw_utils import ( get_csv_onsets, get_audio_ids, get_audio_jams_onsets, map_timing, _get_jams_onsets, ) ``` -------------------------------- ### Compare audio and converted onsets Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Iterates through and prints the audio onsets alongside the converted score onsets for comparison. ```python for i in range(len(audio_onsets)): print(audio_onsets[i], converted_onsets[i]) ``` -------------------------------- ### Define Genre Datasets Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/visualisation/ultimate_guitar_analysis.ipynb Initializes dictionaries containing genre counts for Ultimate Guitar and ChoCo datasets. ```python import matplotlib.pyplot as plt import pandas as pd data_ultimate = { "genre": [ "Rock", "Pop", "Folk", "Country", "Religious Music", "R&b, Funk & Soul", "Soundtrack", "World Music", "Electronic", "Metal", "Hip Hop", "Jazz", "Reggae & Ska", "Classical", "Comedy", "Blues", "Disco", "Experimental", "New Age", "Darkwave", ], "count": [ 454128, 148142, 139728, 89670, 46372, 35899, 31876, 25776, 20851, 18328, 17895, 7187, 6734, 5542, 4279, 3447, 1561, 540, 529, 399, ], } rock = 300 + 200 jazz = 113 + 2486 + 456 + 76 classical = 25 + 250 + 54 pop = 890 + 61 + 195 + 100 folk = 1000 data_choco = { "genre": [ "Pop", "Jazz", "Classical", "Rock", "Folk", "Country", "Religious Music", "R&b, Funk & Soul", "Soundtrack", "World Music", "Electronic", "Metal", "Hip Hop", "Reggae & Ska", "Comedy", "Blues", "Disco", "Experimental", "New Age", "Darkwave", ], "count": [ pop, jazz, classical, rock, folk, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], } ``` -------------------------------- ### Evaluate alignment metrics Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Calculates alignment metrics between audio and converted onsets using a specified window size. ```python # get mireval alignment metrics betweeb the two onsets from curses import window from mir_eval import alignment alignment = alignment.evaluate(audio_onsets, converted_onsets, window=0.3) alignment ``` -------------------------------- ### Aligning Score Onsets to Audio Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Iterates through score onsets and finds the corresponding audio time point using the alignment indices. ```python audio_indices = alignment[0] # type: ignore score_indices = alignment[1] # type: ignore # get jams_score onsets which are the value in the 'Start' column of a csv score_onsets = get_csv_onsets(score_file) for onset in score_onsets: onset = float(onset) * FEATURE_RATE print(onset / FEATURE_RATE) # find value in score_indices that is closest to onset idx = np.abs(score_indices - onset).argmin() print(idx, score_indices[idx], audio_indices[idx] / FEATURE_RATE) ``` -------------------------------- ### Load and Preview Results Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/compute_results.ipynb Reads the CSV file into a pandas DataFrame and displays the first few rows. ```python # import the results results = pd.read_csv(results_path) results.head() ``` -------------------------------- ### Citation BibTeX Source: https://github.com/andreamust/chordsync/blob/main/README.md BibTeX entry for citing the ChordSync paper. ```bibtex @inproceedings{poltronieri2024chordsync, title={ChordSync: A Conformer-based Audio-to-Chord Synchroniser}, author={Poltronieri, Andrea and Presutti, Valentina and Rocamora, Martín}, booktitle={Proceedings of the 2024 Sound and Music Computing Conference}, year={2024}, month={July}, location={Porto, Portugal}, publisher={Sound and Music Computing Network}, url={https://smcnetwork.org/smc2024/papers/SMC2024_paper_id205.pdf} } ``` -------------------------------- ### Compare Datasets with Logarithmic Bar Plot Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/visualisation/ultimate_guitar_analysis.ipynb Creates a side-by-side comparison of Ultimate Guitar and ChoCo datasets using a logarithmic scale. ```python # create a log bar plot comparing data from both datasets df_1 = pd.DataFrame(data_ultimate) df_1.set_index("genre", inplace=True) df_2 = pd.DataFrame(data_choco) df_2.set_index("genre", inplace=True) fig, ax = plt.subplots(figsize=(18, 6)) df_1.plot(kind="bar", ax=ax, color="#E8AD05", position=0, width=0.4, logy=True) df_2.plot(kind="bar", ax=ax, color="black", position=1, width=0.4, logy=True) # make labels font bigger plt.xticks(fontsize=15) plt.yticks(fontsize=15) plt.legend(["Ultimate Guitar", "ChoCo"], fontsize=15) plt.title("Number of songs by genre", fontsize=20) plt.ylabel("Number of songs", fontsize=20) plt.xlabel("Genre", fontsize=20) # set background color plt.gca().set_facecolor("#F4F4F4") fig.patch.set_facecolor("#F4F4F4") plt.show() ``` -------------------------------- ### Display Alignment Metrics Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Shows the output metrics including pc, mae, aae, pcs, and perceptual scores. ```text Result: OrderedDict([('pc', 0.7101449275362319), ('mae', 0.060000000000002274), ('aae', 0.35942028985507163), ('pcs', 0.8551441321915333), ('perceptual', 0.6288164017200519)]) ``` -------------------------------- ### Map score onsets to audio timing Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Converts score onsets to audio-aligned onsets using a pre-computed alignment and feature rate. ```python # get jams_score onsets which are the value in the 'Start' column of a csv score_onsets = get_csv_onsets(score_file) converted_onsets = [ map_timing(alignment, float(onset) * FEATURE_RATE) # type: ignore for onset in score_onsets ] converted_onsets = np.array(converted_onsets) converted_onsets = converted_onsets / FEATURE_RATE score_onsets, converted_onsets ``` -------------------------------- ### DTW Alignment Output Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb A sample output showing the mapping between audio and score indices. ```text 0.0 0.0 1.0 1.0 2.0 1.0 3.0 1.0 4.0 1.0 5.0 1.0 6.0 1.0 7.0 1.0 8.0 1.0 9.0 1.0 10.0 1.0 11.0 1.0 12.0 1.0 13.0 1.0 14.0 1.0 15.0 1.0 16.0 1.0 17.0 1.0 18.0 1.0 19.0 1.0 20.0 1.0 21.0 1.0 22.0 1.0 23.0 2.0 24.0 3.0 25.0 4.0 26.0 4.0 27.0 4.0 28.0 5.0 29.0 5.0 30.0 5.0 31.0 6.0 32.0 7.0 33.0 8.0 34.0 9.0 35.0 10.0 36.0 11.0 37.0 12.0 38.0 13.0 39.0 14.0 40.0 15.0 41.0 16.0 42.0 17.0 43.0 17.0 44.0 17.0 45.0 17.0 46.0 18.0 47.0 19.0 48.0 20.0 49.0 21.0 50.0 21.0 51.0 22.0 52.0 23.0 53.0 24.0 54.0 25.0 55.0 26.0 56.0 27.0 57.0 28.0 58.0 29.0 59.0 30.0 60.0 31.0 61.0 32.0 62.0 33.0 63.0 34.0 64.0 35.0 65.0 35.0 66.0 36.0 67.0 37.0 68.0 37.0 69.0 38.0 70.0 39.0 71.0 40.0 72.0 41.0 73.0 42.0 74.0 43.0 75.0 44.0 76.0 44.0 77.0 44.0 78.0 44.0 79.0 45.0 80.0 46.0 81.0 47.0 82.0 48.0 83.0 49.0 84.0 49.0 85.0 49.0 86.0 49.0 87.0 49.0 88.0 49.0 89.0 50.0 90.0 51.0 91.0 52.0 92.0 53.0 93.0 54.0 94.0 55.0 95.0 56.0 96.0 57.0 97.0 58.0 98.0 59.0 99.0 60.0 100.0 61.0 101.0 62.0 102.0 62.0 103.0 62.0 104.0 62.0 105.0 63.0 106.0 64.0 107.0 65.0 108.0 66.0 109.0 66.0 110.0 66.0 111.0 66.0 112.0 66.0 113.0 67.0 114.0 67.0 115.0 67.0 116.0 68.0 117.0 69.0 118.0 70.0 119.0 71.0 120.0 72.0 121.0 73.0 122.0 74.0 123.0 75.0 124.0 76.0 125.0 77.0 126.0 78.0 127.0 79.0 128.0 80.0 129.0 81.0 130.0 82.0 131.0 83.0 132.0 84.0 133.0 85.0 134.0 86.0 135.0 87.0 136.0 88.0 137.0 89.0 137.0 90.0 137.0 91.0 138.0 92.0 139.0 93.0 140.0 94.0 141.0 95.0 142.0 96.0 143.0 97.0 144.0 98.0 145.0 99.0 146.0 100.0 147.0 101.0 148.0 102.0 149.0 103.0 150.0 104.0 151.0 105.0 152.0 106.0 153.0 107.0 154.0 108.0 155.0 109.0 156.0 110.0 157.0 110.0 158.0 110.0 159.0 111.0 160.0 111.0 161.0 111.0 162.0 111.0 163.0 112.0 164.0 113.0 165.0 114.0 166.0 115.0 167.0 116.0 168.0 116.0 169.0 116.0 170.0 116.0 171.0 116.0 172.0 116.0 173.0 116.0 174.0 116.0 175.0 116.0 176.0 116.0 177.0 116.0 178.0 116.0 179.0 116.0 180.0 116.0 181.0 116.0 182.0 116.0 183.0 117.0 184.0 118.0 185.0 119.0 186.0 120.0 187.0 121.0 188.0 122.0 189.0 123.0 190.0 124.0 191.0 125.0 192.0 126.0 193.0 126.0 194.0 126.0 195.0 126.0 196.0 126.0 197.0 127.0 198.0 128.0 199.0 129.0 200.0 130.0 201.0 130.0 202.0 130.0 203.0 130.0 204.0 131.0 205.0 132.0 206.0 133.0 207.0 133.0 208.0 134.0 209.0 134.0 210.0 134.0 211.0 134.0 212.0 134.0 213.0 134.0 214.0 134.0 215.0 134.0 216.0 135.0 217.0 136.0 218.0 137.0 219.0 138.0 220.0 139.0 221.0 140.0 222.0 141.0 223.0 142.0 224.0 143.0 225.0 143.0 226.0 143.0 227.0 144.0 228.0 144.0 229.0 144.0 230.0 144.0 231.0 144.0 232.0 144.0 233.0 145.0 234.0 146.0 235.0 147.0 236.0 148.0 237.0 149.0 238.0 150.0 239.0 151.0 240.0 152.0 241.0 153.0 242.0 154.0 243.0 155.0 244.0 156.0 245.0 156.0 246.0 157.0 247.0 157.0 248.0 158.0 249.0 159.0 250.0 160.0 251.0 161.0 252.0 161.0 253.0 161.0 254.0 161.0 255.0 161.0 256.0 162.0 257.0 162.0 258.0 163.0 259.0 163.0 260.0 164.0 261.0 165.0 262.0 166.0 263.0 167.0 264.0 168.0 265.0 169.0 266.0 169.0 267.0 170.0 268.0 171.0 269.0 172.0 270.0 173.0 271.0 174.0 272.0 174.0 273.0 174.0 274.0 174.0 275.0 174.0 276.0 174.0 277.0 174.0 278.0 174.0 279.0 174.0 280.0 174.0 281.0 174.0 282.0 174.0 283.0 175.0 284.0 176.0 285.0 177.0 286.0 178.0 287.0 179.0 288.0 180.0 289.0 181.0 290.0 182.0 291.0 183.0 292.0 184.0 293.0 185.0 294.0 185.0 295.0 185.0 296.0 185.0 297.0 185.0 ... [Output truncated] ``` -------------------------------- ### Calculating Genre-Specific Means Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/hcdf/compute_results.ipynb Compute performance metrics for each defined genre group. ```python # pop_rock_results pop_rock_means = { "precision": pop_rock_results["precision"].mean().round(4), "recall": pop_rock_results["recall"].mean().round(4), "f1": pop_rock_results["f1_score"].mean().round(4), } jazz_means = { "precision": jazz_results["precision"].mean().round(4), "recall": jazz_results["recall"].mean().round(4), "f1": jazz_results["f1_score"].mean().round(4), } classical_means = { "precision": classical_results["precision"].mean().round(4), "recall": classical_results["recall"].mean().round(4), "f1": classical_results["f1_score"].mean().round(4), } pop_rock_means, jazz_means, classical_means ``` -------------------------------- ### Plain Text Citation Source: https://github.com/andreamust/chordsync/blob/main/README.md Plain text format for citing the ChordSync paper. ```text A. Poltronieri, V. Presutti, and M. Rocamora, "ChordSync: A Conformer-based Audio-to-Chord Synchroniser," in Proceedings of the 2024 Sound and Music Computing Conference, July 2024, Porto, Portugal. Sound and Music Computing Network. ``` -------------------------------- ### Retrieve Score Files Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Lists all CSV score files and selects the first one for processing. ```python # get the list of score files score_files = list(score_path.glob("*.csv")) # get an example score file score_file = score_files[0] score_file.stem ``` -------------------------------- ### Loading Results Data Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/hcdf/compute_results.ipynb Define the path to the results CSV and load it into a pandas DataFrame. ```python results_path = Path( "/home/buzz/PycharmProjects/ChordSync/ChordSync/baselines/hcdf/results/HCDF_results.csv" ) results_path.exists() ``` ```python # import the results results = pd.read_csv(results_path) results.head() ``` -------------------------------- ### Extract JAMS Onsets Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Extracts score onsets from a JAMS file. ```python score_onsets = _get_jams_onsets(jams_score_path / f"{score_file.stem}.jams") len(score_onsets) ``` -------------------------------- ### Iterate through alignment results Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Prints the aligned audio and score indices from the computed alignment object. ```python for i in range(len(alignment[0])): # type: ignore print(alignment[0][i], alignment[1][i]) # type: ignore ``` -------------------------------- ### Verify Results File Path Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/compute_results.ipynb Checks for the existence of the specified DTW results CSV file. ```python results_path = Path("./data/schubert-winterreise/results/schubert_dtw_results-10.csv") results_path.exists() ``` -------------------------------- ### Plot Genre Distribution Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/visualisation/ultimate_guitar_analysis.ipynb Generates a standard bar chart for the Ultimate Guitar dataset. ```python # plot data df = pd.DataFrame(data_ultimate) df.set_index("genre", inplace=True) df.plot(kind="bar", figsize=(10, 6)) plt.title("Number of songs by genre") plt.ylabel("Number of songs") plt.xlabel("Genre") plt.show() ``` -------------------------------- ### Filtering Results by Genre Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/hcdf/compute_results.ipynb Group and filter the results based on specific genre keywords found in the name column. ```python # compute results by genre, by filtering the rows names pop_rock = ["billboard", "isophonics", "uspop", "casd"] jazz = ["weimar"] classical = ["schubert"] # check if any of pop_rock is in the row[0] name pop_rock_results = results[results["name"].str.contains("|".join(pop_rock))] jazz_results = results[results["name"].str.contains("|".join(jazz))] classical_results = results[results["name"].str.contains("|".join(classical))] ``` -------------------------------- ### Define Constants Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/test_score_alignment.ipynb Sets the feature rate constant for processing. ```python # define constants FEATURE_RATE = 10 ``` -------------------------------- ### Calculating Global Means Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/hcdf/compute_results.ipynb Compute the average precision, recall, and f1-score across the entire dataset. ```python # get average for pc, mae, aae, pcs, and perceptual means = { "precision": results["precision"].mean().round(4), "recall": results["recall"].mean().round(4), "f1": results["f1_score"].mean().round(4), } means ``` -------------------------------- ### Calculate Metric Means Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/baselines/dtw/compute_results.ipynb Computes the mean values for specific columns and rounds them to four decimal places. ```python # get average for pc, mae, aae, pcs, and perceptual means = { "pc": results["pc"].mean().round(4), "mae": results["mae"].mean().round(4), "aae": results["aae"].mean().round(4), "pcs": results["pcs"].mean().round(4), "perceptual": results["perceptual"].mean().round(4), } means ``` -------------------------------- ### Plot Logarithmic Genre Distribution Source: https://github.com/andreamust/chordsync/blob/main/ChordSync/visualisation/ultimate_guitar_analysis.ipynb Generates a bar chart with a logarithmic y-axis to better visualize skewed data. ```python # plot it logarithmically df.plot(kind="bar", figsize=(10, 6), logy=True) plt.title("Number of songs by genre (logarithmic)") plt.ylabel("Number of songs") plt.xlabel("Genre") plt.show() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.