Skip to content

Commit 2142ccd

Browse files
authored
[script.module.pysubs2] 1.5.0+matrix.1 (#2362)
1 parent d767a60 commit 2142ccd

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

script.module.pysubs2/addon.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="script.module.pysubs2" name="pysubs2 module" version="1.5.0" provider-name="Tomáš Karabela">
2+
<addon id="script.module.pysubs2" name="pysubs2 module" version="1.5.0+matrix.1" provider-name="Tomáš Karabela">
33
<requires>
44
<import addon="xbmc.python" version="3.0.0"/>
55
</requires>

script.module.pysubs2/changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
1.5.0+matrix.1 (2022-12-04)
2+
- add missing whisper.py file. Thanks for @peno64 for pointing that out
13
1.5.0 (2022-11-30)
24
- update pysubs2 version to 1.5.0
35
1.3.0 (2021-11-10)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
Support for the OpenAI Whisper speech recognition library.
3+
4+
See https://github.com/openai/whisper
5+
6+
"""
7+
8+
from .ssaevent import SSAEvent
9+
from .ssafile import SSAFile
10+
from .time import make_time
11+
from typing import Union, List, Dict, Any
12+
13+
14+
def load_from_whisper(result_or_segments: Union[Dict[str, Any], List[Dict[str, Any]]]) -> SSAFile:
15+
"""
16+
Load subtitle file from OpenAI Whisper transcript
17+
18+
Example:
19+
>>> import whisper
20+
>>> import pysubs2
21+
>>> model = whisper.load_model("base")
22+
>>> result = model.transcribe("audio.mp3")
23+
>>> subs = pysubs2.load_from_whisper(result)
24+
>>> subs.save("audio.ass")
25+
26+
See also:
27+
https://github.com/openai/whisper
28+
29+
Arguments:
30+
result_or_segments: Either a dict with a ``"segments"`` key
31+
that holds a list of segment dicts, or the segment list-of-dicts.
32+
Each segment is a dict with keys ``"start"``, ``"end"`` (float, timestamps
33+
in seconds) and ``"text"`` (str with caption text).
34+
35+
Returns:
36+
:class:`pysubs2.SSAFile`
37+
38+
"""
39+
if isinstance(result_or_segments, dict):
40+
segments = result_or_segments["segments"]
41+
elif isinstance(result_or_segments, list):
42+
segments = result_or_segments
43+
else:
44+
raise TypeError("Expected either a dict with 'segments' key, or a list of segments")
45+
46+
subs = SSAFile()
47+
for segment in segments:
48+
event = SSAEvent(start=make_time(s=segment["start"]), end=make_time(s=segment["end"]))
49+
event.plaintext = segment["text"].strip()
50+
subs.append(event)
51+
52+
return subs

0 commit comments

Comments
 (0)