50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
|
|
"""Compat wrapper para transcripción.
|
|
|
|
Este módulo expone una clase ligera `FasterWhisperTranscriber` que
|
|
reutiliza la implementación del adaptador infra (`TranscribeService`).
|
|
También reexporta utilidades comunes como `write_srt` y
|
|
`dedupe_adjacent_segments` para mantener compatibilidad con código
|
|
legacy que importa estas funciones desde `whisper_project.transcribe`.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Optional
|
|
|
|
from whisper_project.infra.transcribe_adapter import TranscribeService
|
|
from whisper_project.infra.transcribe import (
|
|
write_srt,
|
|
dedupe_adjacent_segments,
|
|
)
|
|
|
|
|
|
class FasterWhisperTranscriber:
|
|
"""Adaptador mínimo que expone la API esperada por código legacy.
|
|
|
|
Internamente reutiliza `TranscribeService.transcribe_faster`.
|
|
"""
|
|
|
|
def __init__(
|
|
self, model: str = "base", compute_type: str = "int8"
|
|
) -> None:
|
|
self._svc = TranscribeService(
|
|
model=model, compute_type=compute_type
|
|
)
|
|
|
|
def transcribe(
|
|
self, file: str, *, srt: bool = False, srt_file: Optional[str] = None
|
|
):
|
|
segments = self._svc.transcribe_faster(file)
|
|
if srt and srt_file and segments:
|
|
write_srt(segments, srt_file)
|
|
return segments
|
|
|
|
|
|
__all__ = [
|
|
"FasterWhisperTranscriber",
|
|
"TranscribeService",
|
|
"write_srt",
|
|
"dedupe_adjacent_segments",
|
|
]
|
|
|