Skip to content

Instantly share code, notes, and snippets.

@danferns
Last active August 28, 2024 10:53
Show Gist options
  • Select an option

  • Save danferns/d35e6980b70b7901b791e38971401835 to your computer and use it in GitHub Desktop.

Select an option

Save danferns/d35e6980b70b7901b791e38971401835 to your computer and use it in GitHub Desktop.
Outputs the tuning of every audio file inside the current folder.

Some music is written in non-440Hz tuning. This script was created to find the tuning of all tracks in your library.

To use this script, ensure that Python (I'm on v3.12) is installed and get the librosa package using pip:

pip install librosa

Then, copy this script inside your music library folder, and execute it using Python.

python ./TuningDetector.py

In the output, you will see the tuning of each track, followed by the track's path (relative to current dir).

import librosa
import os
# create list of all mp3, wav, flac files recursively in a directory
def get_files(directory):
files = []
for root, dirs, file in os.walk(directory):
for f in file:
if f.endswith('.mp3') or f.endswith('.wav') or f.endswith('.flac'):
files.append(os.path.join(root, f))
return files
# load each file in librosa, and extract the key and tuning
for f in get_files('.'):
y, sr = librosa.load(f)
tuning = librosa.estimate_tuning(y=y, sr=sr)
print(tuning, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment