跳到正文
Simon Willison·· 26 天前精选

Willison分享声源定位实践:让编码Agent借助录音、拍手测试迭代

AI 导读

Willison让Claude Code编写声源定位工具,用手机、平板和电脑采样,通过拍手测试与录音回放迭代。他称最终把蜂鸣声定位到约40厘米范围,找到需换电池的探测器。音频由代码分析,并非模型原生听音。

推荐理由

展示如何给编码Agent建立可观察、可验证的现实反馈。原文正文+原站 RSS 时间核验;定位精度属于作者自述,未独立复测。

正文 · AI 翻译

2026年11月9日

我们家有一间杂物间,里面堆满了上次搬家后一直没拆的箱子。几周前,房间里的某个东西开始断断续续地发出哔哔声。每次响声之间的间隔很长,站在房间里想找出声音来源实在让人抓狂,而我又很不想把每个箱子都翻一遍。于是,我让 Claude Code 开发了 Beep Locator,这套软件系统利用散布在房间各处的多台设备,通过三角定位来寻找神秘哔哔声的来源。

这是 Beep Locator 运行一段时间后的样子:

Screenshot of a web app that uses several phones, tablets and laptops as microphones to locate a mystery beeping sound in a room. The left column has an "Add a listener" panel with a QR code and join link, a "Controls" panel with buttons including "Calibrate", "Test beep" and "It just beeped!" plus a "Listen for beeps" checkbox, and a "Mystery beep" note reading "3345 Hz · 3 confirmed · remembered across sessions". Below that, a "Devices" list shows five color-coded listeners (Simon iPhone, New iPad, Old iPad, MacBook Pro, Surface Ultra), each marked "✓ mic working · ✓ speaker working". The main area is a gridded map with a 1 m scale bar that shows the five devices as colored dots and earlier sounds as small timestamped markers. A pink shaded circle near the MacBook Pro is labeled "mystery beep · 2 hearings · within ~41 cm", and beside it a dashed plus marker suggests "add a listener here? could tighten the mystery beep's position by ~12%". Below the map, a "Mystery beep loudness warmer / colder" panel shows a bar for each device: Surface Ultra is loudest at "-6.0 dB ▲ +11.6 dB warmer", with the note "about 6 dB louder means roughly half the distance". At the bottom, a "Sounds located" table lists recent claps and beeps with coordinates, or the warning "arrival times are not physically possible (echo or a different sound?)".

你先运行一个 Python Web 服务器来显示主界面,再通过二维码或网址,把所有能腾出来的设备都连接上,让它们充当监听设备。我用了两台 iPad、一部手机、一台 MacBook Pro 和一台 Surface Ultra。

接着,这些设备会相互播放声音,帮助估算各自的位置。这个功能的效果不太好,所以我加了一个“粗略模式”,可以在空间中拖动设备图标,给出大致位置,再根据这些声音进行调整。

设置好之后,所有设备就开始监听哔哔声!

我还加了一个拍手模式,这样就能在房间的不同位置拍手来测试系统,拍手声会在地图上显示为菱形。这让我更有信心,相信它确实能定位声音。

哔哔声会在地图上显示为一个 X,同时在“已定位的声音”日志中增加一条记录。你可以回放这些声音(依次播放各台设备录到的声音),确认它们是不是你要找的神秘哔哔声,然后点击“这就是神秘哔哔声”进行标记。

确认神秘哔哔声的频率后,系统就会专门监听它,测量每次哔哔声之间的间隔,并利用三角定位得到的位置,在地图上锁定最可能的声源位置。

系统达到了预期效果。它把哔哔声的位置定位到了大约 40 厘米的范围内,于是我翻找了那一堆箱子,找到了一个年头久远、急需更换电池的一氧化碳探测器。

工作原理

我开始和 Claude 一起研究这个问题时,它很快找到了 BeepBeep: A High-Accuracy Acoustic-Based System for Ranging and Localization Using COTS Devices,这篇论文发表于 2007 年,作者是 Chunyi Peng、Guobin Shen、Yongguang Zhang、Yanlin Li 和 Kun Tan。以下是论文摘要:

我们介绍了 BeepBeep 的设计、实现与评估,它是一种基于声学的高精度测距系统。它在自发、临时组网、设备对设备的环境中运行,无需利用任何预先规划的基础设施。这是一种纯软件解决方案,只使用最基本的通用硬件组合——扬声器、麦克风,以及某种形式的设备间通信——因此可以方便地应用于许多低成本传感器平台,以及手机和 PDA 等大多数商用现成移动设备。它通过结合双向感知、自录音和采样计数三种技术来实现高精度。

听起来,这正是我们需要构建的东西!

Beep Locator 运行着一个 Python Web 应用服务器,由它完成大部分工作。监听设备通过 WebSocket 连接到服务器,并显示一个请求浏览器麦克风访问权限的界面。监听设备主要维护一段 60 秒的近期音频缓冲。它们还运行一个简单的哔哔声检测算法(见 detector.js),使用快速傅里叶变换和高通滤波器来识别可能的哔哔声,并将这些事件发送给主服务器。

收到哔哔声报告后,服务器会让一台设备(与服务器之间往返延迟最低的那台)播放一声短促的啁啾声,然后要求所有监听设备上传一段音频,范围从哔哔声响起前约 0.6 秒到啁啾声响起后 0.8 秒。这声啁啾声可以用来对齐各段音频,而这是定位哔哔声的关键一步。

我是如何构建它的

我通过 iPhone 上的 Claude Code Cloud 启动了这个项目,使用的是以 Extra 思考强度模式运行的 Opus 5.5。这是最初那次会话的分享链接,会话开始时,我针对一个新建的空 GitHub 仓库输入了以下提示词:

Write out a problem.md file describing the problem we want to solve

There is a device beeping in a room and I cannot find it

I want to set up several devices - laptops, phones, iPads - around the room all listening at the same time and have them help triangulate where the beep comes from

There needs to be a Python web app which coordinates it all - one device shows a web page for the app, other devices join a URL which turns them into listeners - all via browser WebAudio and WebSockets back to the Python server app

Ideally I wouldn't need to manually input the relative locations of the devices - it would be amazing if they could play sounds to each other in order to locate each other in 2D space - is that even possible though?

于是,我得到了这份 problem.md 文件。在撰写这份文件的过程中,Claude 找到并阅读了 BeepBeep 论文,文件里也介绍了这篇论文。

研究结果看起来不错,于是我告诉它:

Ok try and build it, add a mechanism so you can send new code to the listeners which they will then run automatically - that way I can set everything up in the room and then leave you alone to continue hacking and experiment while I do something else

这让项目推进到了这个阶段:系统的大部分已经构建完成,但还没有真正试着运行过。

我把新仓库克隆到笔记本电脑上,启动了 Claude Code……随后,Fable 5.2 发布了,而这个项目似乎正好可以用来检验它的能力。

我让笔记本电脑上的 Claude Code 启动服务器,然后确保它既能看到正在发生什么,也能在软件运行时实时修改它。

软件里已经内置了这项能力:Opus 5.5 在监听设备上构建了一个 installModule() 方法,可以通过 WebSocket 连接触发。这意味着管理服务器可以在任何一个客户端上执行任意新代码。

在某些设备上,使用麦克风监听的网页每次重新加载都会请求用户授权。有了模块热替换机制,我们就能部署新代码,而不必逐一手动操作每台监听设备。

从那以后,我主要就是坐在笔记本电脑旁,和 Fable 5.2 聊聊当前的情况,偶尔提出一些新功能需求。下面是我用过的一些功能提示词:

I think we need to make it so I can drag things around on the map in “rough mode”, where my job is just to put them roughly where they are, then switch out of rough mode and it attempts to get them accurate

这让我可以在地图上拖动监听设备。

what’s a good way for me to test this I wonder? Can we have it listen for claps, then I could clap and it could identify the location of the clap? [...]

Claps should use a different symbol on the map than beeps

这增加了一个功能:每次我拍手,地图上就会用一个不同于哔哔声的符号来显示。

each symbol on the map should include a HH:MM:SS timestamp

这样就更容易判断,哪个符号可能对应现实中的哪个声音。

The log should show beeps and claps with their timestamps AND have a little play button which, when clicked, replays the recorded noise from each of the listeners in sequence (with clear text on screen showing which listener recorded which snippet) while temporarily turning off microphone recording while that replay plays

现在我可以回放声音了,这让我更容易辨认出,哪段录音才是我要找的神秘哔哔声。

There should be a button next to a recording for “This is the mystery beep” - then I can hit replay to see and then confirm it was the mystery beep if that’s the one I am looking for

Then the system can categorize noises in the future to see if they are likely that same mysterious beep and use that information to build a more accurate idea of where it is

到这一步,我已经很接近目标了。我已经比较确定哔哔声是从哪里传来的,但如果能把监听设备重新摆到那个位置周围,进一步提高定位精度,岂不是更好?

I want a feature for this, I don’t want to have to restart each listening device etc, I want to be able to click a “Reposition the devices” button which lets me switch into repositioning, then I click “Repositioned” and it puts me into Rough mode and asks me to roughly locate them, then I do that and click, then it starts up again. The previous session can be read-only viewed through the app.

而且我还有一台闲置设备,于是又说:

add a feature where the map includes a spot that is a suggestion for a location that it would be useful to add a listener at - based on data collected so far

给 Claude Code 装上耳朵

我觉得这个项目最有意思的地方在于,我证明了给 Claude Code 装上耳朵是可行的。

Claude(目前)还不支持原生音频输入,但它可以运行 JavaScript 和 Python 代码,分析麦克风采集到的音频。

我让它运行一个 Web 服务器,通过 WebSocket 连接多台监听设备,再让它在这些设备上通过 WebAudio 启用麦克风,并建立连接,以便通过 WebSocket 向设备发送新的 JavaScript 代码来执行。

之后,我基本上就可以让 Claude 自己折腾这个问题,查询音频日志,并重新配置它的耳朵,帮助自己解决问题。

这让我想起几周前在 GitHub Universe 上听说的一个类似技巧。Martin Woodward 告诉我,他调试 GitHub Universe Badge 电脑时,会先通过 USB-C 把它们接到电脑上,再用摄像头对准它们的屏幕,这样他的编程智能体就能判断更新是否正常生效。

琢磨怎样让编程智能体感知周围的世界,实在太有意思了。

来源:Simon Willison · simonwillison.net