reab5555 commited on
Commit
e4e0456
·
verified ·
1 Parent(s): ac5de2e

Update voice_analysis.py

Browse files
Files changed (1) hide show
  1. voice_analysis.py +13 -4
voice_analysis.py CHANGED
@@ -23,14 +23,23 @@ def diarize_speakers(audio_path):
23
  pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization-3.1", use_auth_token=hf_token)
24
  diarization = pipeline(audio_path)
25
 
26
- # Identify the most frequent speaker
27
  speaker_segments = {}
28
  for turn, _, speaker in diarization.itertracks(yield_label=True):
29
  if speaker not in speaker_segments:
30
- speaker_segments[speaker] = 0
31
- speaker_segments[speaker] += turn.end - turn.start
 
 
 
 
 
 
 
 
32
 
33
- most_frequent_speaker = max(speaker_segments, key=speaker_segments.get)
 
34
 
35
  return diarization, most_frequent_speaker
36
 
 
23
  pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization-3.1", use_auth_token=hf_token)
24
  diarization = pipeline(audio_path)
25
 
26
+ # Identify the speakers and their segments
27
  speaker_segments = {}
28
  for turn, _, speaker in diarization.itertracks(yield_label=True):
29
  if speaker not in speaker_segments:
30
+ speaker_segments[speaker] = []
31
+ speaker_segments[speaker].append((turn.start, turn.end))
32
+
33
+ # Print each voice segment
34
+ print(f"Speaker {speaker}: {turn.start:.2f}s - {turn.end:.2f}s")
35
+
36
+ print("\nSpeaker Summary:")
37
+ for speaker, segments in speaker_segments.items():
38
+ total_duration = sum(end - start for start, end in segments)
39
+ print(f"Speaker {speaker}: Total duration = {total_duration:.2f}s")
40
 
41
+ most_frequent_speaker = max(speaker_segments, key=lambda k: sum(end-start for start, end in speaker_segments[k]))
42
+ print(f"\nMost frequent speaker: {most_frequent_speaker}")
43
 
44
  return diarization, most_frequent_speaker
45