forked from aarnphm/whispercpp
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathexplore.py
42 lines (31 loc) · 1011 Bytes
/
explore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Demonstrate how to use the C++ binding directly.
"""
from __future__ import annotations
import sys
import functools as f
from os import environ
from pathlib import Path
import whispercpp as w
_model: w.Whisper | None = None
_MODEL_NAME = environ.get("GGML_MODEL", "tiny")
@f.lru_cache(maxsize=1)
def get_model() -> w.Whisper:
global _model
if _model is None:
_model = w.Whisper.from_pretrained(_MODEL_NAME)
return _model
def main(argv: list[str]) -> int:
"""CLI entrypoint for demonstrating how to use the API binding directly."""
if len(argv) < 1:
sys.stderr.write("Usage: explore.py <audio file>\n")
sys.stderr.flush()
return 1
path = argv.pop(0)
assert Path(path).exists()
params = get_model().params.with_print_realtime(True).build()
assert _model is not None
_model.context.full(params, w.api.load_wav_file_mono(Path(path).__fspath__()))
return 0
if __name__ == "__main__":
raise SystemExit(main(sys.argv[1:]))