跳到正文
Simon Willison·· 2 小时前AI 评分22

用 Claude 定位神秘蜂鸣声:Beep Locator 如何把误差缩小到 40cm

Locating the source of a mysterious beep with Claude

AI 导读

Simon Willison 用 Claude Code 构建了 Beep Locator,一套基于 Python Web 服务器与多设备 WebSocket 的声源三角定位系统,最终将蜂鸣声位置锁定在约 40cm 范围内,找到了一台电量耗尽的旧一氧化碳探测器。

正文 · 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 服务器来显示主界面,然后使用二维码或 URL 连接尽可能多的设备作为监听器——我用了两台 iPad、一部手机、一台 MacBook Pro 和一台 Surface Ultra。

然后这些设备会互相播放声音,以帮助估算它们的位置。这个方法效果不太好,所以我添加了一个“粗略模式”,你可以在空间中拖动它们的图标来提供大致位置,然后根据那些声音进行调整。

设置完成后,所有设备都会监听哔声!

我还添加了拍手模式,这样我就可以通过在房间不同位置拍手来测试它——在地图上显示为菱形。这帮助我确信它能够定位声音。

哔声在地图上显示为 X,并在“已定位声音”日志中显示为一行。你可以重放这些声音(依次从每台设备播放)来确认它们就是你正在寻找的神秘哔声,然后点击“这就是神秘哔声”将其标记为如此。

一旦你确认了神秘哔声的频率,系统就会监听它,测量哔声之间的间隔,并利用三角定位的位置锁定地图上最可能的位置。

系统按预期工作。它把哔声的位置定位在约 40 厘米范围内,然后我翻遍了那堆特定的箱子,发现了一个急需更换电池的老式一氧化碳探测器。

工作原理

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

我们介绍了 BeepBeep 的设计、实现和评估,这是一个高精度的基于声学的测距系统。它在自发、自组织和设备到设备的上下文中运行,不依赖任何预先规划的基础设施。它是一个纯软件解决方案,只使用最基本的一组商用硬件——一个扬声器、一个麦克风以及某种形式的设备到设备通信——因此它可以很容易地应用于许多低成本传感器平台以及大多数商用现成移动设备,如手机和 PDA。它通过三种技术的组合实现了高精度:双向感知、自记录和样本计数。

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

Beep Locator 运行一个 Python Web 应用服务器,承担了大部分工作。监听设备随后通过 WebSocket 连接到该服务器,并呈现一个请求浏览器麦克风权限的 UI。监听器主要通过录制最近音频的 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 在监听器上构建了一个 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 上听到的一个类似 hack,Martin Woodward 告诉我,他一直在调试 GitHub Universe Badge 计算机,方法是通过 USB-C 将它们连接到一台电脑,然后将网络摄像头对准它们的屏幕,这样他的编码代理就能判断更新是否正常工作。

想办法让编码代理感知周围的世界,是一件非常有趣的事。

来源:Simon Willison · simonwillison.net