Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -39,6 +39,7 @@ import librosa
|
|
39 |
import noisereduce as nr
|
40 |
import soundfile as sf
|
41 |
|
|
|
42 |
logger = logging.getLogger(__name__)
|
43 |
|
44 |
# Configure logging
|
@@ -223,16 +224,21 @@ def transcribe_video_with_speakers(video_path):
|
|
223 |
speaker = segment["speaker"]
|
224 |
end = segment["end"]
|
225 |
start = segment["start"]
|
226 |
-
if speaker not in speaker_audio:
|
227 |
-
speaker_audio[speaker] = []
|
228 |
if end > start and (end - start) > 0.05: # Require >50ms duration
|
229 |
-
|
230 |
-
|
|
|
|
|
231 |
# Collapse and truncate speaker audio
|
232 |
speaker_sample_paths = {}
|
233 |
audio_clip = AudioFileClip(speech_audio_path)
|
234 |
for speaker, segments in speaker_audio.items():
|
235 |
speaker_clips = [audio_clip.subclip(start, end) for start, end in segments]
|
|
|
|
|
|
|
|
|
|
|
236 |
combined_clip = concatenate_audioclips(speaker_clips)
|
237 |
truncated_clip = combined_clip.subclip(0, min(30, combined_clip.duration))
|
238 |
|
|
|
39 |
import noisereduce as nr
|
40 |
import soundfile as sf
|
41 |
|
42 |
+
|
43 |
logger = logging.getLogger(__name__)
|
44 |
|
45 |
# Configure logging
|
|
|
224 |
speaker = segment["speaker"]
|
225 |
end = segment["end"]
|
226 |
start = segment["start"]
|
|
|
|
|
227 |
if end > start and (end - start) > 0.05: # Require >50ms duration
|
228 |
+
if speaker not in speaker_audio:
|
229 |
+
speaker_audio[speaker] = [(segment["start"], segment["end"])]
|
230 |
+
else:
|
231 |
+
speaker_audio[speaker].append((segment["start"], segment["end"]))
|
232 |
# Collapse and truncate speaker audio
|
233 |
speaker_sample_paths = {}
|
234 |
audio_clip = AudioFileClip(speech_audio_path)
|
235 |
for speaker, segments in speaker_audio.items():
|
236 |
speaker_clips = [audio_clip.subclip(start, end) for start, end in segments]
|
237 |
+
# Add a check to ensure speaker_clips is not empty
|
238 |
+
if not speaker_clips:
|
239 |
+
logger.warning(f"No valid audio segments found for speaker {speaker} meeting the duration requirement. Skipping sample creation.")
|
240 |
+
continue # Skip the rest of the loop for this speaker
|
241 |
+
|
242 |
combined_clip = concatenate_audioclips(speaker_clips)
|
243 |
truncated_clip = combined_clip.subclip(0, min(30, combined_clip.duration))
|
244 |
|