GroovyMorning_RLAC

Latency Calculation and Master-Slave Synchronization

In a distributed system like GroovyMorning, where audio captured by a Java recorder is analyzed by a Python segmenter, synchronization is a constant challenge. The Master Sync mechanism was designed to ensure exact correspondence between the Java stream and the Python segmenter.

The Problem: Stream Drift

Several factors introduce an offset (latency) between two servers listening to the same radio stream URL:

The Solution: On-the-fly Audio Fingerprinting

A simplified acoustic fingerprinting technique is used to calculate the actual offset between the two instances. The technical process unfolds as follows:

1. Fingerprint Generation (Java Side)

The Java recorder waits for the first segments of the continuous recording to be written to disk. As soon as segment No. 5 is available (about 5 seconds after startup), a fingerprint is extracted:

2. Synchronization Request (/api/sync_offset)

This binary is transmitted via a POST request to the Python segmenter, accompanied by the information positionInSeconds=5. This informs the Python segmenter about the audio state on the Java side at time T=5s.

3. Delta Calculation (Python Side)

A rolling buffer of the audio currently being processed is maintained by the Python segmenter. Upon receiving the fingerprint:

4. Applying Recalibration

The delta received by the Java recorder is stored in the masterOffsetSeconds variable.

Why Not Limit to System Time?

While system time (NTP) synchronizes clocks, it does not guarantee the synchronization of stream content. A radio stream can have a variable delay due to broadcasting servers (CDNs). Fingerprinting proves to be the only reliable method to ensure segmentation based on the sound content actually perceived on both sides.

This “Master Sync” mechanism allows GroovyMorning to achieve high precision in chronicle extraction.

French version