Skip to content

Commit c15fff5

Browse files
authored
Merge pull request #166 from scottmonster/typing
add type support for model.py
2 parents 75f665b + a3f0ffd commit c15fff5

5 files changed

Lines changed: 152 additions & 2 deletions

File tree

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
include README.md LICENSE pybind11/LICENSE version.txt
2+
include pywhispercpp/model.pyi
3+
include pywhispercpp/py.typed
24
graft pybind11/include
35
graft pybind11/tools
46
graft src

pywhispercpp/model.pyi

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
from __future__ import annotations
2+
3+
from typing import Any, Callable, Dict, List, Optional, TextIO, Tuple, TypedDict, Union
4+
5+
import numpy as np
6+
import numpy.typing as npt
7+
8+
AudioArray = npt.NDArray[np.float32]
9+
AudioInput = Union[str, AudioArray]
10+
11+
12+
class GreedyParams(TypedDict):
13+
best_of: int
14+
15+
16+
class BeamSearchParams(TypedDict):
17+
beam_size: int
18+
patience: float
19+
20+
21+
class Segment:
22+
t0: int
23+
t1: int
24+
text: str
25+
probability: float
26+
27+
def __init__(self, t0: int, t1: int, text: str, probability: float = np.nan)->None: ...
28+
def __str__(self)->str: ...
29+
def __repr__(self)->str: ...
30+
31+
32+
class Model:
33+
_new_segment_callback: Optional[Callable[[Segment], None]]
34+
35+
def __init__(
36+
self,
37+
model: str = 'tiny',
38+
models_dir: Optional[str] = None,
39+
params_sampling_strategy: int = 0,
40+
redirect_whispercpp_logs_to: Union[bool, TextIO, str, None] = False,
41+
use_openvino: bool = False,
42+
openvino_model_path: Optional[str] = None,
43+
openvino_device: str = 'CPU',
44+
openvino_cache_dir: Optional[str] = None,
45+
*,
46+
n_threads: Optional[int] = None,
47+
n_max_text_ctx: int = 16384,
48+
offset_ms: int = 0,
49+
duration_ms: int = 0,
50+
translate: bool = False,
51+
no_context: bool = False,
52+
single_segment: bool = False,
53+
print_special: bool = False,
54+
print_progress: bool = True,
55+
print_realtime: bool = False,
56+
print_timestamps: bool = True,
57+
token_timestamps: bool = False,
58+
thold_pt: float = 0.01,
59+
thold_ptsum: float = 0.01,
60+
max_len: int = 0,
61+
split_on_word: bool = False,
62+
max_tokens: int = 0,
63+
audio_ctx: int = 0,
64+
initial_prompt: Optional[str] = None,
65+
prompt_tokens: Optional[Tuple[Any, ...]] = None,
66+
prompt_n_tokens: int = 0,
67+
language: str = '',
68+
suppress_blank: bool = True,
69+
suppress_non_speech_tokens: bool = False,
70+
temperature: float = 0.0,
71+
max_initial_ts: float = 1.0,
72+
length_penalty: float = -1.0,
73+
temperature_inc: float = 0.2,
74+
entropy_thold: float = 2.4,
75+
logprob_thold: float = -1.0,
76+
no_speech_thold: float = 0.6,
77+
greedy: GreedyParams = {'best_of': -1},
78+
beam_search: BeamSearchParams = {'beam_size': -1, 'patience': -1.0},
79+
vad: bool = False,
80+
vad_model_path: Optional[str] = None,
81+
**params
82+
)->None: ...
83+
84+
def transcribe(
85+
self,
86+
media: AudioInput,
87+
n_processors: Optional[int] = None,
88+
new_segment_callback: Optional[Callable[[Segment], None]] = None,
89+
*,
90+
n_threads: Optional[int] = None,
91+
n_max_text_ctx: int = 16384,
92+
offset_ms: int = 0,
93+
duration_ms: int = 0,
94+
translate: bool = False,
95+
no_context: bool = False,
96+
single_segment: bool = False,
97+
print_special: bool = False,
98+
print_progress: bool = True,
99+
print_realtime: bool = False,
100+
print_timestamps: bool = True,
101+
token_timestamps: bool = False,
102+
thold_pt: float = 0.01,
103+
thold_ptsum: float = 0.01,
104+
max_len: int = 0,
105+
split_on_word: bool = False,
106+
max_tokens: int = 0,
107+
audio_ctx: int = 0,
108+
initial_prompt: Optional[str] = None,
109+
prompt_tokens: Optional[Tuple[Any, ...]] = None,
110+
prompt_n_tokens: int = 0,
111+
language: str = '',
112+
suppress_blank: bool = True,
113+
suppress_non_speech_tokens: bool = False,
114+
temperature: float = 0.0,
115+
max_initial_ts: float = 1.0,
116+
length_penalty: float = -1.0,
117+
temperature_inc: float = 0.2,
118+
entropy_thold: float = 2.4,
119+
logprob_thold: float = -1.0,
120+
no_speech_thold: float = 0.6,
121+
greedy: GreedyParams = {'best_of': -1},
122+
beam_search: BeamSearchParams = {'beam_size': -1, 'patience': -1.0},
123+
extract_probability: bool = False,
124+
vad: bool = False,
125+
vad_model_path: Optional[str] = None,
126+
**params
127+
) -> List[Segment]: ...
128+
129+
def get_params(self) -> Dict[str, Any]: ...
130+
@staticmethod
131+
def get_params_schema() -> Dict[str, Dict[str, Any]]: ...
132+
@staticmethod
133+
def lang_max_id() -> int: ...
134+
def print_timings(self) -> None: ...
135+
@staticmethod
136+
def system_info() -> Any: ...
137+
@staticmethod
138+
def available_languages() -> List[str]: ...
139+
@staticmethod
140+
def _load_audio(media_file_path: str) -> AudioArray: ...
141+
def auto_detect_language(
142+
self,
143+
media: AudioInput,
144+
offset_ms: int = 0,
145+
n_threads: int = 4,
146+
) -> Tuple[Tuple[str, np.float32], Dict[str, np.float32]]: ...
147+
def __del__(self) -> None: ...
148+

pywhispercpp/py.typed

Whitespace-only changes.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def get_version() -> str:
258258
packages=find_packages('.'),
259259
package_dir={'': '.'},
260260
include_package_data=True,
261-
package_data={'pywhispercpp': []},
261+
package_data={'pywhispercpp': ["*.pyi", "py.typed"]},
262262
long_description_content_type="text/markdown",
263263
license='MIT',
264264
entry_points={

whisper.cpp

Submodule whisper.cpp updated 808 files

0 commit comments

Comments
 (0)