Spaces:
Running
Running
jhj0517
commited on
Commit
·
6c42d0c
1
Parent(s):
b88d9c4
Add factory function
Browse files
modules/whisper/data_classes.py
CHANGED
|
@@ -30,6 +30,22 @@ class Segment(BaseModel):
|
|
| 30 |
no_speech_prob: Optional[float] = Field(default=None, description="Probability that it's not speech")
|
| 31 |
words: Optional[List['Word']] = Field(default=None, description="List of words contained in the segment")
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
class Word(NamedTuple):
|
| 35 |
start: Optional[float] = None
|
|
|
|
| 30 |
no_speech_prob: Optional[float] = Field(default=None, description="Probability that it's not speech")
|
| 31 |
words: Optional[List['Word']] = Field(default=None, description="List of words contained in the segment")
|
| 32 |
|
| 33 |
+
@classmethod
|
| 34 |
+
def from_faster_whisper(cls,
|
| 35 |
+
seg: faster_whisper.transcribe.Segment):
|
| 36 |
+
return cls(
|
| 37 |
+
id=seg.id,
|
| 38 |
+
text=seg.text,
|
| 39 |
+
start=seg.start,
|
| 40 |
+
end=seg.end,
|
| 41 |
+
tokens=seg.tokens,
|
| 42 |
+
temperature=seg.temperature,
|
| 43 |
+
avg_logprob=seg.avg_logprob,
|
| 44 |
+
compression_ratio=seg.compression_ratio,
|
| 45 |
+
no_speech_prob=seg.no_speech_prob,
|
| 46 |
+
words=seg.words
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
|
| 50 |
class Word(NamedTuple):
|
| 51 |
start: Optional[float] = None
|
modules/whisper/faster_whisper_inference.py
CHANGED
|
@@ -102,11 +102,7 @@ class FasterWhisperInference(BaseTranscriptionPipeline):
|
|
| 102 |
segments_result = []
|
| 103 |
for segment in segments:
|
| 104 |
progress(segment.start / info.duration, desc="Transcribing..")
|
| 105 |
-
segments_result.append(Segment(
|
| 106 |
-
start=segment.start,
|
| 107 |
-
end=segment.end,
|
| 108 |
-
text=segment.text
|
| 109 |
-
))
|
| 110 |
|
| 111 |
elapsed_time = time.time() - start_time
|
| 112 |
return segments_result, elapsed_time
|
|
|
|
| 102 |
segments_result = []
|
| 103 |
for segment in segments:
|
| 104 |
progress(segment.start / info.duration, desc="Transcribing..")
|
| 105 |
+
segments_result.append(Segment.from_faster_whisper(segment))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
elapsed_time = time.time() - start_time
|
| 108 |
return segments_result, elapsed_time
|