@@ -29,11 +29,23 @@ class Segment(BaseModel):
29
29
avg_logprob : Optional [float ] = Field (default = None , description = "Average log probability of the tokens" )
30
30
compression_ratio : Optional [float ] = Field (default = None , description = "Compression ratio of the segment" )
31
31
no_speech_prob : Optional [float ] = Field (default = None , description = "Probability that it's not speech" )
32
- words : Optional [List ['Word' ]] = Field (default = [] , description = "List of words contained in the segment" )
32
+ words : Optional [List ['Word' ]] = Field (default = None , description = "List of words contained in the segment" )
33
33
34
34
@classmethod
35
35
def from_faster_whisper (cls ,
36
36
seg : faster_whisper .transcribe .Segment ):
37
+ if seg .words is not None :
38
+ words = [
39
+ Word (
40
+ start = w .start ,
41
+ end = w .end ,
42
+ word = w .word ,
43
+ probability = w .probability
44
+ ) for w in seg .words
45
+ ]
46
+ else :
47
+ words = None
48
+
37
49
return cls (
38
50
id = seg .id ,
39
51
seek = seg .seek ,
@@ -45,15 +57,15 @@ def from_faster_whisper(cls,
45
57
avg_logprob = seg .avg_logprob ,
46
58
compression_ratio = seg .compression_ratio ,
47
59
no_speech_prob = seg .no_speech_prob ,
48
- words = [] if seg . words is None else seg . words
60
+ words = words
49
61
)
50
62
51
63
52
- class Word (NamedTuple ):
53
- start : Optional [float ] = None
54
- end : Optional [float ] = None
55
- word : Optional [str ] = None
56
- probability : Optional [float ] = None
64
+ class Word (BaseModel ):
65
+ start : Optional [float ] = Field ( default = None , description = "Start time of the word" )
66
+ end : Optional [float ] = Field ( default = None , description = "Start time of the word" )
67
+ word : Optional [str ] = Field ( default = None , description = "Word text" )
68
+ probability : Optional [float ] = Field ( default = None , description = "Probability of the word" )
57
69
58
70
59
71
class BaseParams (BaseModel ):
0 commit comments