**Brief description of the task:**
Develop a Python script for automatically merging **two tracks from an Audacity project** (English and Polish) into a single file, following these conditions:
1. Polish segments follow strictly after English segments.
2. The pauses between segments should be the same.
3. Overlaps between Polish and English segments are not allowed.
---
### **Main steps:**
1. **Export tracks from Audacity**
- Load the Audacity project (*.aup), export both tracks into synchronized audio files (format of choice).
2. **Speech segment detection**
- Determine start/end timestamps of segments in both tracks (algorithm of choice: VAD, ML model, energy analysis).
3. **Segment matching**
- For each English segment `E_N`, find the Polish segment `P_M` that begins **after** the end of `E_N`.
- If `P_M` is too long and overlaps with `E_{N+1}`:
- **Shift** the start of `E_{N+1}` (and all subsequent segments) so that there is a fixed pause (for example, 500 ms) between `P_M` and `E_{N+1}`.
4. **Generate the final audio**
- Combine segments in order: `E_1` → `P_1` → pause → `E_2` → `P_2` → pause → and so on.
- Save all segments with their original content unchanged.
---
### **Clarifications:**
- **Input data**: Audacity project with two tracks.
- **Key rules**:
- The order of English segments does not change.
- All segments are fully preserved.
- Pauses between `P_M` and `E_{N+1}` are the same for all segments.
- **Technologies**:
- Segment detection — at the developer's discretion.
- Segment shifting algorithm — dynamic (e.g., recursive correction of timestamps).
- **Conflict handling**:
- If shifting is impossible (e.g., not enough space), log a warning.
---
**Example of shift logic implementation:**
- If `P_M` ends at `t=5.0`, and `E_{N+1}` starts at `t=4.5`:
1. Calculate overlap: `4.5 - 5.0 = -0.5 seconds`.
2. Shift `E_{N+1}` by `0.5 seconds + X` (where `X` is the fixed pause).
3. Update timestamps of all subsequent segments.
**Goal:** Full automation without data loss, maintaining natural order of segments and pauses.
In the attachment, an example of the desired result (Efezjan 6 - D12_done.mp3),
and an example of the source file (Efezjan 6 - D12.aup3):
https://drive.google.com/file/d/1YQ1h95bzXD4M3EXCdNaFLADJUeQw1zTY/view?usp=sharing