File size: 1,005 Bytes
dd5bcef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Speaker management utilities."""
from typing import List

from src.vtt import create_vtt
from src.whisper import TranscriptSegment


class SpeakerManager:
    """Manages speaker renaming operations."""

    @staticmethod
    def rename_speaker(
        transcripts: List[TranscriptSegment],
        old_speaker: str,
        new_speaker: str
    ) -> str:
        """
        Rename a speaker in transcripts and return updated VTT.

        Args:
            transcripts: List of transcript segments
            old_speaker: Current speaker name
            new_speaker: New speaker name

        Returns:
            Updated VTT content as string
        """
        if not transcripts:
            return ""

        # Update speaker names in place
        for transcript in transcripts:
            if transcript.speaker == old_speaker:
                transcript.speaker = new_speaker

        # Regenerate VTT with updated speakers
        vtt = create_vtt(transcripts)
        return vtt.content