Simon Willison 用 Claude Code 定位房间里的神秘蜂鸣
Locating the source of a mysterious beep with Claude
Simon Willison 用 Claude Code 搭建的 Beep Locator 把房间间歇蜂鸣定位到约 40cm,并在对应纸箱里找到急需换电池的旧一氧化碳探测器。
9th November 2026
我们家有一间储物间,里面堆满了上次搬家后我们至今仍未拆开的箱子。几周前,那个房间里有东西开始间歇性地发出哔哔声。这些哔声间隔足够长,站在房间里试图确定噪音来源令人沮丧,而我实在不想把每一个箱子都翻一遍。于是我让 Claude Code 构建了 Beep Locator,一套用散布在房间各处的多台设备对神秘哔声来源进行三角定位的软件系统。
下面是 Beep Locator 运行一段时间之后的样子:

你运行 Python Web 服务器来显示主界面,然后用二维码或 URL 连接尽可能多能腾出来的设备充当监听器——我用的是两台 iPad、一部手机、一台 MacBook Pro 和一台 Surface Ultra。
这些设备随后会互相播放声音,以帮助估算各自的位置。这效果并不特别好,于是我加了一个“粗略模式”,你可以在空间中拖动它们的图标来给出大致位置,这些位置随后会根据那些声音进行调整。
一旦设置完成,所有设备都会监听哔声!
我还加了一个拍手模式,以便在房间不同位置拍手来测试——这些拍手在地图上显示为菱形。这帮助我建立信心,确信它能够定位声音。
哔声会在地图上显示为 X,并在“已定位声音”日志里记上一行。你可以重放这些声音(依次来自每台设备),确认它们就是你要找的神秘哔声,然后点击“这就是神秘哔声”把它们标记出来。
一旦你确认了神秘哔声的频率,系统就会专门监听它,测量各次哔声之间的间隔,并利用三角定位的位置在地图上锁定最可能的位置。
系统达到了预期效果。它把哔声位置定位到大约 40cm 以内,然后我翻了那一堆特定的箱子,找到一个急需更换电池的老旧一氧化碳探测器。
工作原理
当我开始和 Claude 一起处理这个问题时,它很快翻出了 BeepBeep:一种使用 COTS 设备进行测距与定位的高精度声学系统,这是 Chunyi Peng、Guobin Shen、Yongguang Zhang、Yanlin Li 和 Kun Tan 于 2007 年发表的论文。以下是该论文的摘要:
我们介绍了 BeepBeep 的设计、实现与评估。它是一套高精度的基于声学的测距系统,在自发、自组织且设备对设备的场景中运行,不依赖任何预先规划的基础设施。它是纯软件解决方案,只使用最基本的一套商用硬件——扬声器、麦克风以及某种形式的设备间通信——因此很容易应用于许多低成本传感器平台,以及手机和 PDA 等大多数商用现成移动设备。它通过结合三种技术实现高精度:双向感知、自录音和样本计数。
这听起来正是我们需要构建的东西!
Beep Locator 运行一个承担大部分工作的 Python Web 应用服务器。监听设备随后通过 WebSocket 连接到该服务器,并呈现一个请求浏览器麦克风访问权限的界面。监听端主要通过录制最近 60 秒的音频缓冲区来工作。它们还会运行一个简单的蜂鸣检测算法(见 detector.js),该算法使用快速傅里叶变换和高通滤波器来识别潜在的蜂鸣。它将这些事件发送到主服务器。
当一次蜂鸣被报告时,服务器会让一台设备播放一段短促的啁啾声(选择与服务器往返时间最短的那台设备),然后要求每个监听端上传从蜂鸣前约 0.6 秒到该啁啾声之后 0.8 秒的片段。这段啁啾声使各片段能够彼此对齐,这是定位蜂鸣的关键步骤。
我是如何构建它的
我通过我的 iPhone 使用 Claude Code Cloud 开始了这个项目,Opus 5.5 以 Extra thinking effort 模式运行。这是那个共享的起始会话,它针对一个新建的空 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 为监听端构建了一个可通过 WebSocket 连接触发的 installModule() 方法,这意味着管理服务器可以在其任意客户端上执行任意新代码。
在某些设备上,监听麦克风的网页每次重新加载时都会请求用户权限。热替换模块机制意味着我们可以部署新代码,而无需依次手动与每一台监听设备交互。
从那时起,我的参与主要是坐在笔记本电脑旁,与 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 上听到的一个类似 hack:Martin Woodward 告诉我,他当时在调试 GitHub Universe Badge computers,做法是通过 USB-C 把它们插到一台电脑上,再用网络摄像头对准它们的屏幕,这样他的编程代理就能判断更新是否正常工作。
想办法让编程代理感知周围的世界,真的非常有趣。
来源:Simon Willison · simonwillison.net