Spaces:
Paused
Paused
Commit ·
41b4ddd
1
Parent(s): 0e4f7a9
Timestamps line up with the original recording (add back trimmed leading silence)
Browse files
src/audio_processor/converter.py
CHANGED
|
@@ -103,7 +103,11 @@ class AudioConverter:
|
|
| 103 |
# hallucinating at the end when it encounters long silence.
|
| 104 |
# top_db=20 was too aggressive and cut quiet speech at the edges
|
| 105 |
# of phone recordings; 35 dB only removes genuine dead air.
|
| 106 |
-
audio,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
# Step 6: Save processed audio
|
| 109 |
sf.write(output_path, audio, self.target_sr)
|
|
|
|
| 103 |
# hallucinating at the end when it encounters long silence.
|
| 104 |
# top_db=20 was too aggressive and cut quiet speech at the edges
|
| 105 |
# of phone recordings; 35 dB only removes genuine dead air.
|
| 106 |
+
audio, kept = librosa.effects.trim(audio, top_db=35)
|
| 107 |
+
# Seconds cut from the start. Timestamps are measured on the trimmed
|
| 108 |
+
# audio, so the engine adds this back to line them up with the
|
| 109 |
+
# original recording the user replays.
|
| 110 |
+
self.last_trim_offset = float(kept[0]) / self.target_sr if len(kept) else 0.0
|
| 111 |
|
| 112 |
# Step 6: Save processed audio
|
| 113 |
sf.write(output_path, audio, self.target_sr)
|
src/transcription/engine.py
CHANGED
|
@@ -101,6 +101,7 @@ class TranscriptionEngine:
|
|
| 101 |
raise ValueError(f"Invalid audio file: {error}")
|
| 102 |
|
| 103 |
processed_path = self.converter.preprocess(file_path)
|
|
|
|
| 104 |
audio, sr = sf.read(processed_path)
|
| 105 |
# Use sample-count duration — always exact regardless of container format.
|
| 106 |
# metadata.duration comes from sf.info() on the original MP3/M4A which
|
|
@@ -181,6 +182,13 @@ class TranscriptionEngine:
|
|
| 181 |
else:
|
| 182 |
logger.warning("Diarization requested but not available (pyannote.audio missing or HF_TOKEN not set).")
|
| 183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
finally:
|
| 185 |
Path(processed_path).unlink(missing_ok=True)
|
| 186 |
|
|
|
|
| 101 |
raise ValueError(f"Invalid audio file: {error}")
|
| 102 |
|
| 103 |
processed_path = self.converter.preprocess(file_path)
|
| 104 |
+
lead_in = getattr(self.converter, "last_trim_offset", 0.0)
|
| 105 |
audio, sr = sf.read(processed_path)
|
| 106 |
# Use sample-count duration — always exact regardless of container format.
|
| 107 |
# metadata.duration comes from sf.info() on the original MP3/M4A which
|
|
|
|
| 182 |
else:
|
| 183 |
logger.warning("Diarization requested but not available (pyannote.audio missing or HF_TOKEN not set).")
|
| 184 |
|
| 185 |
+
# Leading silence was trimmed before transcription; shift every
|
| 186 |
+
# timestamp back onto the original recording's timeline.
|
| 187 |
+
if lead_in > 0 and result.segments:
|
| 188 |
+
for seg in result.segments:
|
| 189 |
+
seg["start"] = round(seg["start"] + lead_in, 3)
|
| 190 |
+
seg["end"] = round(seg["end"] + lead_in, 3)
|
| 191 |
+
|
| 192 |
finally:
|
| 193 |
Path(processed_path).unlink(missing_ok=True)
|
| 194 |
|