chroma_cqt
Analyze audio files to extract chroma features for music analysis. Converts audio signals into chromatic content representation showing note timing and amplitude.
Instructions
Computes the chroma CQT of the given audio time series using librosa.
The chroma CQT is a representation of the audio signal in terms of its
chromatic content, which is useful for music analysis.
The chroma CQT is computed using the following parameters:
- path_audio_time_series_y: The path to the audio time series (CSV file).
It's sometimes better to take harmonics only
- hop_length: The number of samples between frames.
- fmin: The minimum frequency of the chroma feature.
- n_chroma: The number of chroma bins (default is 12).
- n_octaves: The number of octaves to include in the chroma feature.
The chroma CQT is saved to a CSV file with the following columns:
- note: The note name (C, C#, D, etc.).
- time: The time position of the note in seconds.
- amplitude: The amplitude of the note at that time.
The path to the CSV file is returned.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path_audio_time_series_y | Yes | ||
| hop_length | No | ||
| fmin | No | ||
| n_chroma | No | ||
| n_octaves | No |
Implementation Reference
- src/mcp_music_analysis/server.py:96-143 (handler)The chroma_cqt tool handler: loads audio time series, computes chroma CQT using librosa.feature.chroma_cqt, saves note,time,amplitude to CSV, returns path.@mcp.tool() def chroma_cqt( path_audio_time_series_y: str, hop_length: int = 512, fmin: float = None, n_chroma: int = 12, n_octaves: int = 7, ) -> str: """ Computes the chroma CQT of the given audio time series using librosa. The chroma CQT is a representation of the audio signal in terms of its chromatic content, which is useful for music analysis. The chroma CQT is computed using the following parameters: - path_audio_time_series_y: The path to the audio time series (CSV file). It's sometimes better to take harmonics only - hop_length: The number of samples between frames. - fmin: The minimum frequency of the chroma feature. - n_chroma: The number of chroma bins (default is 12). - n_octaves: The number of octaves to include in the chroma feature. The chroma CQT is saved to a CSV file with the following columns: - note: The note name (C, C#, D, etc.). - time: The time position of the note in seconds. - amplitude: The amplitude of the note at that time. The path to the CSV file is returned. """ y = np.loadtxt(path_audio_time_series_y, delimiter=";") chroma_cq = librosa.feature.chroma_cqt( y=y, hop_length=hop_length, fmin=fmin, n_chroma=n_chroma, n_octaves=n_octaves, ) # Save the chroma_cq to a CSV file name = path_audio_time_series_y.split("/")[-1].split(".")[0] + "_chroma_cqt" chroma_cq_path = os.path.join(tempfile.gettempdir(), name + ".csv") notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"] time_frames = np.arange(chroma_cq.shape[1]) time_seconds = librosa.frames_to_time(time_frames, hop_length=hop_length) with open(chroma_cq_path, "w") as f: f.write("note,time,amplitude\n") for i, note in enumerate(notes): for t_index, amplitude in enumerate(chroma_cq[i]): t = time_seconds[t_index] f.write(f"{note},{t},{amplitude}\n") # Return the path to the CSV file return chroma_cq_path