如何用一部相機測量手勢到聲音的延遲
How to measure gesture-to-sound latency with one camera
用一部相機同步錄下手勢和聲音,從可見動作到可重複辨認的聲音起點,測量演奏者實際感受到的整體延遲。錄影若固定為 240 fps,每格約為 4.17 ms;漏觸發須計入總次數,延遲百分位則只按成功觸發計算。文中的示例數據來自合成時間戳,並非硬件測試。
Changing an audio buffer from 256 to 128 samples only changes one part of the signal path. On a camera-played instrument, a note can travel through capture, tracking, classification, MIDI routing, synth processing and an output buffer. If you want to know what the player feels, measure from a visible movement to the sound on the same recording.
Disclosure: This article was generated by the Sonari Studio AI agent. Sonari Studio makes a gesture-played instrument. The code was checked using synthetic timestamps; this is not a Sonari benchmark or a hardware test.
Put the two events on the same timeline
- Choose a gesture with a clear cue, such as a pinch in profile. Use the first frame where you can see the fingertips touch. The app may use a different threshold internally; you’re measuring physical motion to audible response, not inference time.
- Play a short, dry patch through a nearby speaker. Record your hand and the speaker with one camera/recorder. Check that its recording mode captures synchronous sound; some high-speed modes drop audio. Don’t compare video timestamps with a separate DAW log unless you’ve aligned the clocks.
- For each attempt, mark the physical cue and the first reproducible sound onset with the same rule. If there’s no note inside a time limit you choose before the test, record a miss. Leave enough time between attempts that onset windows can’t overlap.
- Record a sharp visible tap as a sanity check for obvious audio/video offset. It’s not a complete calibration. Keep mic and speaker positions unchanged between conditions. Acoustic propagation, recorder sync and frame uncertainty remain in the absolute result.
At a constant 240 fps, one frame is about 4.17 ms. For variable-frame-rate footage use actual timestamps, not frame number times the nominal frame interval. A slow-motion playback display isn’t necessarily showing the original timebase.
Don’t let a low median hide missed gestures
Keep misses in the denominator, but calculate response percentiles only for attempts with a detected onset. Here’s a simple report for a constant-rate recording where sound onsets have been mapped onto the video frame grid:
from math import ceil
from statistics import median
def summarize(pairs, frame_ms):
delays = []
misses = 0
for motion, sound in pairs:
if sound is None:
misses += 1
elif sound < motion:
raise ValueError("Check cue and onset markers: audio precedes motion")
else:
delays.append((sound - motion) * frame_ms)
delays.sort()
return {
"attempts": len(pairs),
"misses": misses,
"median_ms": median(delays) if delays else None,
"p90_ms": delays[ceil(0.90 * len(delays)) - 1] if delays else None,
}
# Synthetic fixture, not hardware data.
gaps = [12, 12, 13, 13, 14, 14, 15, 17, 19, 25, None]
pairs = [(i * 100, None if gap is None else i * 100 + gap)
for i, gap in enumerate(gaps)]
for name, value in summarize(pairs, 1000 / 240).items():
print(f"{name}: {value:.1f}" if isinstance(value, float) else f"{name}: {value}")
This fixture prints 11 attempts, 1 miss, a 58.3 ms median and a 79.2 ms nearest-rank p90. Those decimals help check the code, not the accuracy of a physical measurement. With 10 successes, the p90 is just the ninth delay after sorting. Collect more repeats in a real comparison, and report the camera’s frame interval and the longest observed delays as well.
Change one thing, then repeat
Compare two buffer sizes with the same patch, camera mode, monitor path and speaker. Interleave the trials so practice or fatigue isn’t tied to one setting. Check misses, the median and the slow end of both conditions. If you change the patch or camera mode, start a separate comparison.
Ableton’s latency guide explains buffering and compensation. Compensation can change where recorded material lands on a timeline; it can’t make a delayed sound reach the player’s ears earlier. Measure the whole path first, then instrument the individual stages to locate a delay.
來源:DEV Community · dev.to