-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring back Realtime SRT generation, check if WAV provided, minor code…
… improvements
- Loading branch information
1 parent
ac311a0
commit 8ea16d3
Showing
7 changed files
with
135 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,52 @@ | ||
from typing import Optional | ||
from typing import Optional, Iterable, Iterator | ||
from faster_whisper.transcribe import Segment | ||
|
||
|
||
class SegmentsIterable(Iterable): | ||
segments: list = None | ||
index: int = None | ||
length: int = 0 | ||
__segments_iterable: Iterator[Segment] | ||
|
||
def __init__(self, segments: Iterable[Segment]): | ||
self.__segments_iterable = segments.__iter__() | ||
self.segments = [] | ||
|
||
def __iter__(self): | ||
if self.index is not None: | ||
self.index = 0 | ||
return self | ||
|
||
def __next_list(self): | ||
if self.index < self.length: | ||
item = self.segments[self.index] | ||
self.index += 1 | ||
return item | ||
else: | ||
raise StopIteration | ||
|
||
def __next_iter(self): | ||
try: | ||
item = next(self.__segments_iterable) | ||
self.segments.append(item) | ||
self.length += 1 | ||
return item | ||
except StopIteration: | ||
self.index = 0 | ||
raise StopIteration | ||
|
||
def __next__(self): | ||
if self.index is not None: | ||
return self.__next_list() | ||
|
||
return self.__next_iter() | ||
|
||
|
||
class Subtitles: | ||
segments: list | ||
segments: SegmentsIterable[Segment] | ||
language: str | ||
output_path: Optional[str] = None | ||
|
||
def __init__(self, segments: list[Segment], language: str): | ||
def __init__(self, segments: SegmentsIterable[Segment], language: str): | ||
self.language = language | ||
self.segments = segments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters