- Клиент 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/
40 lines
970 B
Python
40 lines
970 B
Python
import os
|
|
from typing import Optional
|
|
|
|
from config import config
|
|
|
|
|
|
def diarize(audio_path: str, hf_token: Optional[str] = None) -> list[dict]:
|
|
if hf_token is None:
|
|
hf_token = config.HF_TOKEN
|
|
|
|
if not hf_token:
|
|
return _fallback_diarization()
|
|
|
|
try:
|
|
from pyannote.audio import Pipeline
|
|
|
|
pipeline = Pipeline.from_pretrained(
|
|
"pyannote/speaker-diarization-3.1",
|
|
use_auth_token=hf_token,
|
|
)
|
|
|
|
diarization = pipeline(audio_path)
|
|
|
|
segments = []
|
|
for turn, _, speaker in diarization.itertracks(yield_label=True):
|
|
segments.append({
|
|
"start": round(turn.start, 2),
|
|
"end": round(turn.end, 2),
|
|
"speaker": speaker,
|
|
})
|
|
|
|
segments.sort(key=lambda s: s["start"])
|
|
return segments
|
|
|
|
except Exception as e:
|
|
return _fallback_diarization()
|
|
|
|
|
|
def _fallback_diarization() -> list[dict]:
|
|
return []
|