Sound Source Localization with AI Coding Tools: Building a Beep Locator
A developer used AI coding tools and five everyday devices to build Beep Locator, a distributed microphone system that traced an intermittent beep to an old carbon monoxide detector within roughly 40 centimeters. This article examines the system’s architecture, audio synchronization, frequency filtering, time-difference-of-arrival calculations, and deployment workflow, along with the practical limits that determine localization accuracy.
An occasional electronic beep can be surprisingly difficult to track down. It may last only a few milliseconds, disappear for several minutes, and seem to come from a different direction each time.
One software developer encountered exactly this problem after moving. Somewhere among the unpacked boxes in a storage room, a device kept beeping. The long intervals between sounds made the usual approach—getting closer and listening again—impractical.
Instead, the developer used AI coding tools to build Beep Locator, a sound source localization system assembled from everyday devices. It narrowed the search to roughly 40 centimeters, leading to an old carbon monoxide detector buried inside a box.
Beyond solving a household annoyance, the project illustrates how to turn an uncertain sensory problem into a measurable engineering task. The following sections examine its architecture, signal-processing methods, localization algorithm, and practical deployment considerations.
1. Why an Intermittent Beep Is Hard to Locate
Human hearing estimates direction partly from differences in when a sound reaches each ear, known as interaural time difference (ITD), and differences in loudness, known as interaural level difference (ILD).
The storage-room scenario made those cues difficult to use for three reasons:
- Sparse signals. Each beep lasted only tens of milliseconds, with gaps potentially lasting several minutes. There was no continuous sound to follow.
- Multipath propagation. Boxes and room surfaces reflected and diffracted the sound, making its apparent direction unreliable.
- Limited opportunities to move. A person could not scan every corner before the beep ended. Multiple listening points needed to capture the same event.
Professional microphone arrays can address this kind of problem, but their cost and setup requirements were disproportionate to the task.
The developer already had several phones, tablets, and laptops. Combining their microphones offered an alternative: a distributed, virtual microphone array.
That shifted the challenge from “Where does the beep seem to come from?” to two more concrete questions:
- How can independent devices record a shared event on comparable timelines?
- How can differences between those recordings reveal the source position?
2. System Architecture: Turning Five Devices into a Microphone Array
Beep Locator relies on time difference of arrival (TDOA).
Sound travels through air at approximately 340 meters per second. A beep reaches nearby microphones before more distant ones. If the microphone coordinates and relative arrival times are known, those differences constrain the source location.
In principle, at least four suitably positioned microphones provide the three independent TDOA measurements needed to estimate a three-dimensional position. In practice, geometry, measurement noise, and possible ambiguities affect whether that estimate is reliable.
The first major engineering challenge is synchronization. Independent devices do not share an audio clock. Comparing their microphone timestamps directly can introduce errors of several milliseconds—enough to create substantial distance errors.
2.1 Synchronizing Recordings with a Reference Sound
One practical approach is to play a known, short reference sound, such as a 1 kHz tone burst, while the listening devices record.
The workflow is:
- Designate one device as the controller and the others as listening nodes.
- Have the controller play a reference signal and record its playback timing.
- Capture that signal on all listening nodes.
- Detect its arrival in each recording and use those observations to align the audio timelines.
There is an important distinction between aligning a reference sound and synchronizing clocks: the reference sound itself takes different amounts of time to reach different microphones. Those propagation delays must be accounted for when estimating clock offsets. A single calibration also does not eliminate subsequent clock drift.
Cross-correlation is a standard way to estimate the relative delay between two audio signals:
# Illustration: estimate the time delay between two signals using cross-correlationimport numpy as npdef compute_delay(sig1, sig2, sample_rate=44100):# Normalize and window the signals before processing (omitted)corr = np.correlate(sig1, sig2, mode='full')delay_samples = np.argmax(corr) - (len(sig2) - 1)return delay_samples / sample_rate
The correlation peak indicates the relative shift at which the two signals best match. For a short, distinctive sound, it can support sub-millisecond delay estimation under favorable recording conditions.
2.2 Improving Signal-to-Noise Ratio with Frequency Filtering
A storage room may contain persistent background noise, including low-frequency ventilation hum and occasional rustling. An electronic beep, by contrast, often concentrates its energy in a relatively narrow frequency range—for example, between 2 kHz and 4 kHz.
The system uses a fast Fourier transform (FFT) to inspect the recording’s frequency content. It retains the target frequency band and transforms the result back into the time domain.
def bandpass(signal, sample_rate, low_freq, high_freq):spectrum = np.fft.rfft(signal)freqs = np.fft.rfftfreq(len(signal), d=1/sample_rate)spectrum[(freqs < low_freq) | (freqs > high_freq)] = 0filtered = np.fft.irfft(spectrum)return filtered
The developer first examined a captured beep to identify its frequency range, then applied the same filtering to the recordings from all devices.
This reduces out-of-band noise and can make correlation peaks easier to identify. It does not, however, remove reflected copies of the beep that occupy the same frequency band. Multipath remains a source of timing error.
3. Mapping Device Positions: Manual Calibration and Greedy Placement
Arrival-time measurements are useful only when the microphone positions are also known.
The developer initially tried acoustic ranging: devices would take turns playing and recording sounds, allowing the system to estimate their distances from one another and reconstruct their relative positions.
In practice, the resulting errors could exceed half a meter. Feeding inaccurate microphone coordinates into the localization solver would shift the estimated source position.
The project therefore switched to manual position calibration.
A browser interface displayed a floor plan of the storage room. The user dragged device icons to match their physical locations. This made placement straightforward and avoided the accumulated errors of automatic ranging.
Fine-grained control on a screen is not the same as physical measurement accuracy, however. The map scale, actual device placement, and microphone heights still determine how accurately the coordinates represent the room.
Suggesting Where to Add Another Device
The system also introduced a placement recommendation feature.
Using the existing device coordinates and an initial estimate of the source region, a greedy algorithm evaluated where an additional microphone could most reduce location uncertainty.
Rather than adding devices arbitrarily, the user could place the next listening node where it was expected to provide the most useful additional constraint.
4. The Localization Algorithm: From Delays to Coordinates
Once device positions and corrected arrival-time differences are available, estimating the source location becomes a nonlinear least-squares problem.
Let:
- (p_i) be the position of microphone (i),
- (p_0) be the reference microphone position,
- (\tau_i) be the arrival-time difference relative to that reference,
- (x) be the unknown source position,
- (c) be the speed of sound.
The ideal relationship is:
[
c\tau_i = |x-p_i|-|x-p_0|
]
The left-hand side converts a time difference into a path-length difference. The right-hand side expresses that same difference geometrically.
Real measurements do not satisfy every equation exactly. The solver therefore searches for the source position that minimizes the combined residual error, using an iterative method such as gradient descent or Gauss–Newton.
// Illustration: part of an iterative least-squares solver (pseudocode)function solveTDOA(anchorPositions, delays, c) {let guess = initialGuess(anchorPositions, delays);for (let iter = 0; iter < 50; iter++) {const jacobian = computeJacobian(guess, anchorPositions, c);const residuals = computeResidual(guess, anchorPositions, delays, c);const delta = solveLinearSystem(jacobian, residuals);guess = guess.add(delta);if (delta.norm() < 1e-4) break;}return guess;}
This is an algorithm sketch rather than a complete implementation. The residual definitions, Jacobian, and update convention must agree.
Why Device Geometry Matters
The developer found that three-dimensional estimates were more stable when devices were spread out and placed at different heights.
When all microphones lie close to the same plane, vertical position becomes difficult to resolve. This explains why the placement recommendation feature favored height diversity as well as horizontal separation.
More microphones help, but their arrangement matters as much as their number.
5. Engineering the Prototype into a Reusable Tool
The localization mathematics was only one part of the project. The system also needed a practical way to collect audio, transfer useful recordings, and expose errors during debugging.
Browser-Based Microphone Capture
Each device accessed its microphone through the browser’s getUserMedia API. The Web Audio API handled audio capture and preprocessing.
This avoided requiring a native application on every phone, tablet, or laptop, reducing the deployment burden.
Local Detection and Selective Uploads
Because the beep could occur only once every few minutes, continuously uploading every microphone stream would transfer mostly irrelevant audio.
Instead, each device listened locally and used an energy threshold to detect a possible event. When triggered, it saved a clip containing approximately 0.5 seconds before and after the event, then uploaded that segment to the controller.
This preserved useful context while limiting unnecessary network traffic.
An Interface for Inspection and Calibration
The web interface displayed:
- Device positions.
- Estimated source locations.
- Controls for adjusting microphone coordinates.
- Reference-tone recalibration.
- Waveforms and frequency spectra for individual channels.
These inspection tools helped separate different classes of failure. An inconsistent result might come from a poorly captured beep, inaccurate coordinates, or synchronization problems rather than from the location solver itself.
Feedback for Iterative Deployment
When repeated estimates disagreed, the system could suggest adding another device or moving an existing one closer to the suspected source.
Localization therefore became an iterative process: collect a measurement, inspect the result, improve placement, and measure again.
6. Understanding the Roughly 40-Centimeter Result
The estimated location eventually led the developer to a box containing an old carbon monoxide detector. Its low-battery warning was responsible for the intermittent beep.
An error of roughly 40 centimeters was sufficient to identify the relevant box.
Several factors supported that result.
Audio Sampling Provided Fine Timing Resolution
At a sampling rate of 44.1 kHz, one sample spans approximately 22.7 microseconds. At 340 meters per second, that corresponds to about 7.7 millimeters of acoustic path difference.
That is a sampling interval, not a guarantee of millimeter-level position accuracy. Synchronization error, reflections, microphone coordinates, and array geometry all contribute to the final uncertainty.
Filtering Made the Target Easier to Detect
Restricting analysis to the beep’s frequency band reduced unrelated noise and improved the usefulness of the recorded signal for delay estimation.
The benefit was primarily better signal isolation, not the elimination of all reflected sound.
Additional Devices Added Redundancy
With five microphones and one selected as the reference, the system has four reference-based TDOA equations for three source coordinates.
That redundancy allows least-squares fitting to reduce the influence of some random measurement errors. It improves robustness, although it cannot automatically correct systematic timing or placement errors.
7. How AI Coding Tools Accelerated Development
The developer did not manually write every component from scratch. AI coding tools generated much of the supporting code from natural-language requirements, including modules for:
- Audio capture.
- FFT-based filtering.
- Cross-correlation.
- Coordinate estimation.
- The surrounding application workflow.
This shortened the path from an idea to a testable prototype and allowed more attention to go toward architecture, calibration, and debugging.
The project demonstrates a practical strength of AI-assisted development: when a developer understands the problem and the required algorithms, a coding assistant can quickly produce scaffolding that is useful for experimentation.
It does not remove the need for technical judgment. Signal-processing code can run successfully while using an incorrect timing convention or an invalid synchronization assumption. Geometry code can return coordinates even when the microphone arrangement provides poor constraints.
The developer still needs enough understanding to verify the generated implementation against the physical system.
8. Other Applications of Distributed Sound Localization
The same combination of distributed microphones and TDOA estimation applies beyond finding an electronic beep.
Potential uses include:
- Smart-home troubleshooting: locating dripping water or an appliance warning sound.
- Industrial diagnostics: identifying the acoustic source of abnormal machinery noise.
- Conference systems: tracking a speaker’s location to guide microphone adjustment or steering.
- Security monitoring: estimating the origin of events such as breaking glass or gunshots.
For larger deployments, recordings could be uploaded to cloud-based audio-processing infrastructure for centralized computation.
The broader lesson is not tied to a particular platform: existing devices can sometimes be combined into a useful sensing system when no single available tool solves the problem directly.
9. Code Availability and Deployment Workflow
The source account describes the project as publicly available in the open-source community. The snippets here illustrate core ideas rather than providing a complete application.
A reproduction workflow follows these steps:
- Prepare at least four microphone-equipped devices. Connect them to the same local network.
- Deploy the controller and web application. The server can be built with Node.js or Python.
- Enter device positions. Match the map coordinates to the physical microphone locations.
- Run reference-sound calibration. Play the short reference tone, such as the 1 kHz signal described earlier, and align recordings while accounting for propagation delay.
- Wait for the target sound. Let the nodes capture the event and submit their clips for localization.
- Inspect the estimated position. Search the indicated area and refine the setup if necessary.
If estimates are inaccurate, start by checking:
- Whether synchronization remains valid.
- Whether device coordinates match their actual locations.
- Whether persistent background noise is obscuring the event.
- Whether microphone placement provides enough spatial separation and height variation.
Conclusion
Beep Locator turned an intermittent household annoyance into a tractable signal-processing problem.
Its core workflow was straightforward: capture the same event on multiple devices, align their recordings, isolate the relevant frequencies, estimate arrival-time differences, and solve for a source position. The practical difficulty lay in making those measurements trustworthy.
AI coding tools accelerated implementation, but the result still depended on sound engineering decisions about timing, geometry, filtering, and validation.
The project offers a useful model for technical prototyping: define the physical problem clearly, translate it into measurable quantities, and use available hardware and software to test the idea.
