submaster/whisper_project
Cesar Mendivil c22767d3d4 Refactor SRT to Kokoro synthesis script for improved CLI functionality and compatibility
- Updated `srt_to_kokoro.py` to provide a CLI entrypoint with argument parsing.
- Enhanced error handling and logging for better user feedback.
- Introduced a compatibility layer for legacy scripts.
- Added configuration handling via `config.toml` for endpoint and API key.
- Improved documentation and comments for clarity.

Enhance PipelineOrchestrator with in-process transcriber fallback

- Implemented `InProcessTranscriber` to handle transcription using multiple strategies.
- Added support for `srt_only` flag to return translated SRT without TTS synthesis.
- Improved error handling and logging for transcriber initialization.

Add installation and usage documentation

- Created `INSTALLATION.md` for detailed setup instructions for CPU and GPU environments.
- Added `USAGE.md` with practical examples for common use cases and command-line options.
- Included a script for automated installation and environment setup.

Implement SRT burning utility

- Added `burn_srt.py` to facilitate embedding SRT subtitles into video files using ffmpeg.
- Provided command-line options for style and codec customization.

Update project configuration management

- Introduced `config.py` to centralize configuration loading from `config.toml`.
- Ensured that environment variables are not read to avoid implicit overrides.

Enhance package management with `pyproject.toml`

- Added `pyproject.toml` for modern packaging and dependency management.
- Defined optional dependencies for CPU and TTS support.

Add smoke test fixture for SRT

- Created `smoke_test.srt` as a sample subtitle file for testing purposes.

Update requirements and setup configurations

- Revised `requirements.txt` and `setup.cfg` for better dependency management and clarity.
- Included installation instructions for editable mode and local TTS support.
2025-10-25 00:00:02 -07:00
..
2025-10-23 21:54:13 -07:00

Proyecto de ejemplo: Transcriptor Whisper (CPU)

Un pequeño proyecto que demuestra cómo transcribir archivos de audio en CPU usando tres enfoques:

  • openai-whisper (paquete original)

Proyecto de ejemplo: Transcriptor y doblador (Whisper + Coqui TTS)

Este repo contiene utilidades para transcribir audio/video en CPU usando distintos backends de Whisper y para generar doblaje por segmentos usando Coqui TTS. Está pensado como una base reproducible y ligera para pruebas en CPU.

Contenido principal

  • transcribe.py — CLI principal: transcripción (openai-whisper / transformers / faster-whisper), generación de SRT (incluyendo fallback), síntesis TTS por segmento y pipeline de doblaje (replace / mix).
  • process_video.py — pipeline alto nivel (extraer audio, transcribir, traducir/opcional, generar SRT y quemar subtítulos en video).

Requisitos del sistema

  • ffmpeg (disponible en PATH)
  • Para Coqui TTS se recomienda usar Miniforge/Conda con Python 3.11 en CPU.

Instalación rápida

  1. Entorno ligero (solo transcripción con faster-whisper y dependencias mínimas):
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
  1. Entorno para Coqui TTS (recomendado si vas a sintetizar/doblar):
# Instalar Miniforge/Miniconda si no lo tienes, luego:
conda create -n tts_env python=3.11 -y
conda activate tts_env
# PyTorch CPU + TTS
python -m pip install --index-url https://download.pytorch.org/whl/cpu torch torchvision torchaudio
python -m pip install TTS faster-whisper

Nota: en la sesión de ejemplo se creó tts_env y se instaló TTS y faster-whisper.

Uso — ejemplos prácticos

  1. Transcribir un audio y generar SRT (faster-whisper, modelo base):
# desde el entorno donde tengas faster-whisper disponible
python whisper_project/transcribe.py \
	--file whisper_project/dailyrutines.audio.wav \
	--backend faster-whisper --model base --srt
  1. Generar SRT de fallback (sin texto) — divide en segmentos uniformes:
python whisper_project/transcribe.py -f path/to/audio.wav -b transformers --srt --srt-fallback
  1. Transcripción por segmentos (extrae piezas y transcribe cada una):
python whisper_project/transcribe.py -f path/to/audio.wav --segment-transcribe --srt --srt-segment-seconds 8
  1. Doblaje por segmentos (replace = reemplaza voz original):
# usando el entorno tts_env donde instalaste Coqui TTS
conda activate tts_env
python whisper_project/transcribe.py \
	--file whisper_project/dailyrutines.audio.wav \
	--segment-transcribe --srt --srt-file whisper_project/dailyrutines.kokoro.dub.srt \
	--srt-segment-seconds 6 \
	--tts-model tts_models/en/ljspeech/tacotron2-DDC \
	--tts-model-repo tts_models/en/ljspeech/tacotron2-DDC \
	--dub --dub-mode replace --dub-out whisper_project/dailyrutines.kokoro.dub.wav
  1. Doblaje por segmentos (mix = mezcla TTS con original):
python whisper_project/transcribe.py \
	--file whisper_project/dailyrutines.audio.wav \
	--segment-transcribe --dub --dub-mode mix --dub-mix-level 0.7 \
	--tts-model tts_models/en/ljspeech/tacotron2-DDC --dub-out out_mix.wav

Remuxar audio doblado en el MP4 y quemar subtítulos

  1. Reemplazar la pista de audio en el MP4 por la pista doblada (sin recomprimir video):
ffmpeg -y -i dailyrutines.mp4 -i whisper_project/dailyrutines.kokoro.dub.wav -c:v copy -map 0:v:0 -map 1:a:0 -shortest dailyrutines.kokoro.dub.mp4
  1. Quemar subtítulos (hardcode) en el video (requiere re-encode del video):
ffmpeg -y -i dailyrutines.mp4 -vf "subtitles=whisper_project/dailyrutines.kokoro.dub.srt:force_style='FontName=Arial,FontSize=24'" -c:a copy dailyrutines.kokoro.subs.mp4

Notas sobre modelos Hugging Face y tokens

  • Si el repo del modelo TTS o del modelo de ASR es privado necesitarás exportar HUGGINGFACE_HUB_TOKEN en el entorno antes de ejecutar el script para que huggingface_hub.snapshot_download pueda acceder. Ejemplo:
export HUGGINGFACE_HUB_TOKEN="hf_xxx..."

Rendimiento y recomendaciones

  • En CPU usa modelos pequeños (tiny, base) para tiempos aceptables.
  • faster-whisper con compute_type=int8 reduce memoria y acelera en CPU.
  • Para producción con GPU, instala las ruedas de PyTorch/GPU apropiadas y activa gpu=True en las llamadas a TTS y whisper si tu hardware lo permite.

Problemas comunes y troubleshooting

  • "No module named 'faster_whisper'": instala faster-whisper en tu entorno.
  • Coqui TTS tarda en descargar modelos la primera vez (pesan decenas de MB).
  • Si la síntesis TTS es lenta, verifica que torch esté instalado y que TTS use un vocoder optimizado (HifiGAN es el por defecto en los modelos de ejemplo).

¿Quieres que haga esto por ti?

  • Puedo generar el MP4 final (reemplazando pista y/o quemando subtítulos), o ajustar el pipeline de doblaje (p.ej. time-stretch suave). Indica qué prefieres y lo ejecuto localmente en este workspace.