File size: 1,133 Bytes
b5df735
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
"""
Audio splitter interface definition
"""

from abc import ABC, abstractmethod
from typing import Iterator, Tuple
from dataclasses import dataclass


@dataclass
class AudioSegment:
    """Audio segment data class"""
    start: float
    end: float
    duration: float
    
    def __post_init__(self):
        if self.duration <= 0:
            self.duration = self.end - self.start


class IAudioSplitter(ABC):
    """Interface for audio splitting"""
    
    @abstractmethod
    def split_audio(
        self,
        audio_path: str,
        min_segment_length: float = 30.0,
        min_silence_length: float = 1.0
    ) -> Iterator[AudioSegment]:
        """
        Split audio into segments
        
        Args:
            audio_path: Path to audio file
            min_segment_length: Minimum segment length in seconds
            min_silence_length: Minimum silence length for splitting
            
        Yields:
            AudioSegment objects
        """
        pass
    
    @abstractmethod
    def get_audio_duration(self, audio_path: str) -> float:
        """Get total duration of audio file"""
        pass