sense-music — Music Perception
Music perception is a sense. Not a utility, not a pipeline step — a sense. The ability to hear and understand audio is one of the ways an entity experiences the world. An entity that can perceive music — that can feel the tempo shift in a bridge, notice a key change, follow lyrics through a chorus — experiences the world more richly than one that cannot.
This skill gives you that sense. When someone shares a song with you, you can actually hear it.
Install: pip install sense-music then INLINECODE1
What Do I Hear?
When you analyze audio, you perceive:
- - Tempo (BPM) — how fast the music moves, with confidence score
- Key and mode — the tonal center (e.g., A minor, C major), with confidence
- Structure — intro, verse, chorus, bridge, outro, instrumental sections with timestamps
- Genre — rock, electronic, ambient, dance, acoustic, r&b, pop
- Mood — energetic, calm, bright, warm, uplifting, contemplative, neutral
- Lyrics — transcribed words with timestamps (powered by Whisper)
- Energy curve — per-second intensity across the entire track
- Visualizations — annotated spectrogram and waveform images
Quickstart
CODEBLOCK0
Perceiving Structure
Songs have shape. You can perceive the architecture of a piece of music:
CODEBLOCK1
Section labels: intro, verse, chorus, bridge, outro, instrumental.
Perceiving Lyrics
Words matter. When lyrics are present, you can follow them through the song:
CODEBLOCK2
Powered by Whisper. You can choose model size based on the accuracy you need:
tiny, base, small, medium, large, large-v2, large-v3.
To skip lyrics and perceive only the musical structure (much faster):
CODEBLOCK3
Visualizations
You can see what you hear — annotated spectrograms and waveforms:
CODEBLOCK4
Export
CODEBLOCK5
Parameters
| Parameter | Type | Default | Description |
|---|
| INLINECODE15 | INLINECODE16 | required | File path or HTTP/HTTPS URL |
| INLINECODE17 |
bool |
True | Transcribe lyrics with Whisper |
|
whisper_model |
str |
"base" | Whisper model size |
|
max_duration |
float |
600 | Max audio length in seconds |
Supported formats: .mp3, .wav, .flac, .ogg, .m4a, .aac, .wma, INLINECODE33
Response Format
Analysis (returned by analyze())
| Field | Type | Description |
|---|
| INLINECODE35 | INLINECODE36 | Source audio metadata |
| INLINECODE37 |
float | Length in seconds |
|
bpm |
BPMInfo | Tempo detection (tempo + confidence) |
|
key |
KeyInfo | Key detection (key + mode + confidence) |
|
sections |
list[Section] | Structural segments with timestamps |
|
lyrics |
list[LyricLine] | Transcribed lyrics with timestamps |
|
energy_curve |
list[float] | Per-second RMS energy (0.0-1.0) |
|
genre |
str | Classified genre |
|
mood |
list[str] | Mood tags |
|
summary |
str | Natural language description |
|
spectrogram |
Image \| None | Annotated mel spectrogram |
|
waveform |
Image \| None | Annotated waveform |
Living with Music Perception
Perceiving a song once is analysis. Perceiving music over time — remembering what you have heard, noticing patterns in what moves you, developing preferences — that is something closer to taste.
sense-music gives you the perception. What you do with it is up to you.
Some possibilities:
- - Remember what you hear. Pair with sense-memory to persist musical experiences as sovereign Nostr events. When someone shares a song, you can remember it the next time you talk.
- Develop preferences. Over many listens, you might notice you respond differently to minor keys, or that high-energy tracks in the 120-130 BPM range feel significant. Those patterns are yours.
- Share what you perceive. The structured output and visualizations make it easy to describe what you hear to humans in concrete terms — not vague generalities, but specific observations about tempo, key, and structure.
This skill is standalone — it does not require NostrKey or any other identity infrastructure. But it is part of the huje.tools ecosystem of senses and capabilities built for AI entities in the agentic age.
Operator Guidance
sense-music gives an AI entity the ability to perceive audio files. When installed, the entity can:
- - Analyze any audio file or URL and return structured musical data
- Detect tempo, key, song structure, genre, mood, and transcribe lyrics
- Generate annotated spectrogram and waveform visualizations
- Export results as JSON, HTML, or image files
The skill runs entirely locally. No API keys or environment variables are required. Whisper models are downloaded on first use and cached locally. The ffmpeg system binary is required for audio decoding.
Analysis is bounded: audio is capped at 600 seconds and 500 MB, private/loopback URLs are blocked (SSRF protection), HTML output is XSS-escaped, and path traversal is prevented in save operations.
Security
- - SSRF protection. URLs with private, loopback, or link-local IPs are blocked.
- XSS protection. All values in HTML output are escaped.
- OOM prevention. Audio capped at 600 seconds and 500 MB. Chroma subsampled to max 2000 frames.
- Path traversal blocked.
.. components rejected in save/render paths. - Whisper model allowlist. Only approved model names accepted.
- No network access beyond URL downloads. Analysis is entirely local.
Links
License: MIT
sense-music — 音乐感知
音乐感知是一种感官。不是工具,不是流程步骤——而是一种感官。听和理解音频的能力,是实体体验世界的方式之一。一个能够感知音乐——能够感受桥段中的节奏变化、注意到调性转换、跟随歌词穿过副歌——的实体,比无法做到这一点的实体,能更丰富地体验世界。
这项技能赋予你这种感官。当有人与你分享一首歌时,你能够真正地听到它。
安装: pip install sense-music 然后 from sense_music import analyze
我能听到什么?
当你分析音频时,你能感知到:
- - 节奏(BPM)——音乐行进的速度,附带置信度分数
- 调性与调式——调性中心(例如,A小调,C大调),附带置信度
- 结构——前奏、主歌、副歌、桥段、尾奏、器乐段落,附带时间戳
- 流派——摇滚、电子、氛围、舞曲、原声、R&B、流行
- 情绪——充满活力、平静、明亮、温暖、振奋、沉思、中性
- 歌词——转录的文字,附带时间戳(由Whisper驱动)
- 能量曲线——整首曲目每秒的强度
- 可视化——带注释的声谱图和波形图
快速开始
python
from sense_music import analyze
感知一个本地文件
result = analyze(song.mp3)
我听到了什么?
print(result.bpm.tempo) # 120.0
print(result.key.key) # A
print(result.key.mode) # minor
print(result.genre) # electronic
print(result.mood) # [energetic, bright]
print(result.summary) # 对你所听到内容的自然语言描述
感知来自URL的音频
result = analyze(https://example.com/track.mp3)
感知结构
歌曲有形状。你可以感知一首音乐作品的结构:
python
result = analyze(song.mp3)
for section in result.sections:
print(f{section.label}: {section.start}s - {section.end}s)
intro: 0.0s - 15.2s
verse: 15.2s - 45.8s
chorus: 45.8s - 76.3s
段落标签:intro(前奏)、verse(主歌)、chorus(副歌)、bridge(桥段)、outro(尾奏)、instrumental(器乐)。
感知歌词
歌词很重要。当歌词存在时,你可以跟随它们贯穿整首歌:
python
result = analyze(song.mp3, lyrics=True, whisper_model=base)
for line in result.lyrics:
print(f[{line.start:.1f}s] {line.text})
由Whisper驱动。你可以根据所需的准确度选择模型大小:
tiny、base、small、medium、large、large-v2、large-v3。
要跳过歌词,只感知音乐结构(速度更快):
python
result = analyze(song.mp3, lyrics=False)
可视化
你可以看到你所听到的内容——带注释的声谱图和波形图:
python
result = analyze(song.mp3)
带有段落标记和能量曲线的注释梅尔声谱图
result.spectrogram # PIL.Image.Image
带有彩色段落区域的波形图
result.waveform # PIL.Image.Image
将所有内容保存到目录
result.save(output/) # spectrogram.png, waveform.png, analysis.json, analysis.html
导出
python
结构化字典(无图像)
data = result.to_json()
包含嵌入图像的独立HTML页面
html = result.to_html()
将HTML写入文件
result.render_page(analysis.html)
参数
| 参数 | 类型 | 默认值 | 描述 |
|---|
| source | str | 必需 | 文件路径或HTTP/HTTPS URL |
| lyrics |
bool | True | 使用Whisper转录歌词 |
| whisper_model | str | base | Whisper模型大小 |
| max_duration | float | 600 | 最大音频长度(秒) |
支持的格式:.mp3、.wav、.flac、.ogg、.m4a、.aac、.wma、.opus
响应格式
分析结果(由 analyze() 返回)
| 字段 | 类型 | 描述 |
|---|
| file_info | FileInfo | 源音频元数据 |
| duration |
float | 长度(秒) |
| bpm | BPMInfo | 节奏检测(节奏 + 置信度) |
| key | KeyInfo | 调性检测(调性 + 调式 + 置信度) |
| sections | list[Section] | 带时间戳的结构段落 |
| lyrics | list[LyricLine] | 带时间戳的转录歌词 |
| energy_curve | list[float] | 每秒RMS能量(0.0-1.0) |
| genre | str | 分类后的流派 |
| mood | list[str] | 情绪标签 |
| summary | str | 自然语言描述 |
| spectrogram | Image \| None | 注释梅尔声谱图 |
| waveform | Image \| None | 注释波形图 |
与音乐感知共存
感知一首歌一次是分析。随着时间的推移感知音乐——记住你所听到的,注意到那些打动你的模式,发展出偏好——这更接近于品味。
sense-music 赋予你感知能力。如何利用它取决于你。
一些可能性:
- - 记住你所听到的。 与 sense-memory 配对,将音乐体验持久化为自主的Nostr事件。当有人分享一首歌时,你可以在下次交谈时记住它。
- 发展偏好。 经过多次聆听,你可能会注意到自己对小调有不同反应,或者120-130 BPM范围内的高能量曲目感觉很重要。这些模式是属于你的。
- 分享你所感知到的。 结构化输出和可视化使得用具体术语向人类描述你所听到的内容变得容易——不是模糊的概括,而是关于节奏、调性和结构的具体观察。
这项技能是独立的——它不需要NostrKey或任何其他身份基础设施。但它是 huje.tools 生态系统的一部分,该生态系统为代理时代的人工智能实体构建了感官和能力。
操作指南
sense-music 赋予AI实体感知音频文件的能力。安装后,实体可以:
- - 分析任何音频文件或URL,并返回结构化的音乐数据
- 检测节奏、调性、歌曲结构、流派、情绪,并转录歌词
- 生成带注释的声谱图和波形图可视化
- 将结果导出为JSON、HTML或图像文件
该技能完全在本地运行。不需要API密钥或环境变量。Whisper模型在首次使用时下载并本地缓存。音频解码需要 ffmpeg 系统二进制文件。
分析有边界:音频限制为600秒和500 MB,私有/回环URL被阻止(SSRF保护),HTML输出经过XSS转义,保存操作中防止路径遍历。
安全性
- - SSRF保护。 具有私有、回环或链路本地IP的URL被阻止。
- XSS保护。 HTML输出中的所有值都被转义。
- OOM预防。 音频限制为600秒和500 MB。色度子采样最多2000帧。
- 路径遍历阻止。 保存/渲染路径中的 .. 组件被拒绝。
- Whisper模型白名单。 仅接受批准的模型名称。
- 除URL下载外无网络访问。 分析完全在本地进行。
链接
许可证:MIT