- Клиент Novofon DATA API (JSON-RPC, get.calls_report, чанки по 90 дней) - faster-whisper (модель turbo) на CUDA с разделением стереоканалов - Маркировка спикеров: левый канал = caller, правый = callee - Directus: коллекции calls, calls_74951284933, contacts - CLI: process, process-file, export, daemon (polling 5 мин) - Docker Compose для Directus + PostgreSQL - Архив email-парсинга в old/
31 lines
1,018 B
Python
31 lines
1,018 B
Python
from typing import Optional
|
|
from faster_whisper import WhisperModel
|
|
|
|
|
|
_model: Optional[WhisperModel] = None
|
|
|
|
|
|
def get_model(model_size: str = "medium", device: str = "cpu", compute_type: str = "int8") -> WhisperModel:
|
|
global _model
|
|
if _model is None:
|
|
_model = WhisperModel(model_size, device=device, compute_type=compute_type)
|
|
return _model
|
|
|
|
|
|
def transcribe(audio_path: str, model_size: str = "medium", device: str = "cpu", compute_type: str = "int8", language: str = "ru") -> tuple[list[dict], str]:
|
|
model = get_model(model_size, device, compute_type)
|
|
|
|
segments, info = model.transcribe(audio_path, language=language, beam_size=5, vad_filter=True)
|
|
|
|
result = []
|
|
full_text_parts = []
|
|
for seg in segments:
|
|
result.append({
|
|
"start": round(seg.start, 2),
|
|
"end": round(seg.end, 2),
|
|
"text": seg.text.strip(),
|
|
})
|
|
full_text_parts.append(seg.text.strip())
|
|
|
|
full_text = " ".join(full_text_parts)
|
|
return result, full_text
|