feat: fix frontend and activate imports
This commit is contained in:
@@ -1,206 +0,0 @@
|
||||
# Instalación Manual de Bark TTS en t-800
|
||||
|
||||
## Opción A: Instalación Automática (Recomendada)
|
||||
|
||||
```bash
|
||||
# 1. Copiar script a t-800
|
||||
scp scripts/install_bark_tts.sh juan@t-800:/tmp/install_bark_tts.sh
|
||||
|
||||
# 2. Conectarse a t-800
|
||||
ssh juan@t-800
|
||||
|
||||
# 3. Ejecutar instalación
|
||||
chmod +x /tmp/install_bark_tts.sh
|
||||
sudo /tmp/install_bark_tts.sh
|
||||
|
||||
# 4. Verificar instalación
|
||||
curl http://localhost:8000/health
|
||||
```
|
||||
|
||||
## Opción B: Instalación Paso a Paso
|
||||
|
||||
```bash
|
||||
# Conectarse a t-800
|
||||
ssh juan@t-800
|
||||
# Contraseña: apoca11
|
||||
|
||||
# Actualizar sistema
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y python3 python3-pip python3-venv git ffmpeg curl
|
||||
|
||||
# Crear directorio
|
||||
sudo mkdir -p /opt/bark
|
||||
sudo chown juan:juan /opt/bark
|
||||
cd /opt/bark
|
||||
|
||||
# Clonar Bark
|
||||
git clone https://github.com/suno-ai/bark.git
|
||||
cd bark
|
||||
|
||||
# Crear entorno virtual
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
|
||||
# Instalar dependencias
|
||||
pip install --upgrade pip
|
||||
pip install -e .
|
||||
pip install fastapi uvicorn[standard] python-multipart numpy scipy
|
||||
|
||||
# Crear archivo de API
|
||||
cat > bark_api.py << 'PYEOF'
|
||||
from fastapi import FastAPI, HTTPException, Query
|
||||
from fastapi.responses import StreamingResponse
|
||||
from bark import SAMPLE_RATE, generate_audio, preload_models
|
||||
from scipy.io.wavfile import write as write_wav
|
||||
import numpy as np
|
||||
import io
|
||||
|
||||
app = FastAPI(title="Bark TTS API", version="1.0.0")
|
||||
|
||||
print("Preloading Bark models...")
|
||||
preload_models()
|
||||
print("Models loaded!")
|
||||
|
||||
@app.get("/health")
|
||||
async def health_check():
|
||||
return {"status": "healthy", "service": "bark-tts"}
|
||||
|
||||
@app.get("/api/voices")
|
||||
async def list_voices():
|
||||
return {
|
||||
"voices": [
|
||||
{"id": "v2/en_speaker_0", "name": "English Speaker 0", "language": "en"},
|
||||
{"id": "v2/en_speaker_1", "name": "English Speaker 1", "language": "en"},
|
||||
{"id": "v2/en_speaker_6", "name": "English Speaker 6", "language": "en"},
|
||||
{"id": "v2/es_speaker_0", "name": "Spanish Speaker 0", "language": "es"},
|
||||
{"id": "v2/es_speaker_1", "name": "Spanish Speaker 1", "language": "es"},
|
||||
{"id": "v2/es_speaker_3", "name": "Spanish Speaker 3", "language": "es"},
|
||||
]
|
||||
}
|
||||
|
||||
@app.post("/api/generate")
|
||||
async def generate_speech(
|
||||
text: str = Query(..., min_length=1, max_length=500),
|
||||
voice: str = Query(default="v2/en_speaker_1"),
|
||||
speed: float = Query(default=1.0, ge=0.5, le=2.0),
|
||||
output_format: str = Query(default="wav", regex="^(mp3|wav|ogg)$")
|
||||
):
|
||||
try:
|
||||
audio_array = generate_audio(text, history_prompt=voice)
|
||||
|
||||
if speed != 1.0:
|
||||
new_length = int(len(audio_array) / speed)
|
||||
audio_array = audio_array[:new_length]
|
||||
|
||||
audio_buffer = io.BytesIO()
|
||||
write_wav(audio_buffer, SAMPLE_RATE, audio_array)
|
||||
audio_buffer.seek(0)
|
||||
|
||||
return StreamingResponse(
|
||||
audio_buffer,
|
||||
media_type="audio/wav",
|
||||
headers={"Content-Disposition": f"attachment; filename=speech.wav"}
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||
PYEOF
|
||||
|
||||
# Crear servicio systemd
|
||||
cat > /tmp/bark-tts.service << EOF
|
||||
[Unit]
|
||||
Description=Bark TTS API Server
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=juan
|
||||
Group=juan
|
||||
WorkingDirectory=/opt/bark/bark
|
||||
Environment="PATH=/opt/bark/bark/venv/bin"
|
||||
ExecStart=/opt/bark/bark/venv/bin/uvicorn bark_api:app --host 0.0.0.0 --port 8000 --workers 1
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
MemoryMax=4G
|
||||
MemoryHigh=3G
|
||||
CPUQuota=80%
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
sudo mv /tmp/bark-tts.service /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable bark-tts
|
||||
sudo systemctl start bark-tts
|
||||
|
||||
# Verificar
|
||||
sudo systemctl status bark-tts
|
||||
curl http://localhost:8000/health
|
||||
```
|
||||
|
||||
## Prueba de Funcionamiento
|
||||
|
||||
```bash
|
||||
# Test básico
|
||||
curl "http://localhost:8000/api/generate?text=Hello%20World&voice=v2/en_speaker_1" -o test.wav
|
||||
|
||||
# Test desde OpenCCB
|
||||
curl http://t-800:8000/health
|
||||
|
||||
# Ver logs
|
||||
sudo journalctl -u bark-tts -f
|
||||
```
|
||||
|
||||
## Configuración en OpenCCB
|
||||
|
||||
Agregar a `.env`:
|
||||
```bash
|
||||
BARK_API_URL=http://t-800:8000
|
||||
# O para producción:
|
||||
# BARK_API_URL=http://t-800.norteamericano.cl:8000
|
||||
```
|
||||
|
||||
## Solución de Problemas
|
||||
|
||||
### Error: "Out of Memory"
|
||||
```bash
|
||||
# Reducir límite de memoria en systemd
|
||||
sudo systemctl edit bark-tts
|
||||
# Agregar:
|
||||
# [Service]
|
||||
# MemoryMax=2G
|
||||
```
|
||||
|
||||
### Error: "Model not found"
|
||||
```bash
|
||||
# Reinstalar modelos
|
||||
cd /opt/bark/bark
|
||||
source venv/bin/activate
|
||||
python -c "from bark import preload_models; preload_models()"
|
||||
```
|
||||
|
||||
### Servicio no inicia
|
||||
```bash
|
||||
# Ver logs
|
||||
sudo journalctl -u bark-tts -n 50
|
||||
|
||||
# Reiniciar
|
||||
sudo systemctl restart bark-tts
|
||||
```
|
||||
|
||||
## URLs de Acceso
|
||||
|
||||
- **Health**: http://t-800:8000/health
|
||||
- **Voices**: http://t-800:8000/api/voices
|
||||
- **Generate**: http://t-800:8000/api/generate?text=Hello&voice=v2/en_speaker_1
|
||||
|
||||
## Producción (t-800.norteamericano.cl)
|
||||
|
||||
Para producción, asegurar que:
|
||||
1. El puerto 8000 esté abierto en el firewall
|
||||
2. El dominio t-800.norteamericano.cl apunte a la IP correcta
|
||||
3. Usar BARK_API_URL=http://t-800.norteamericano.cl:8000
|
||||
@@ -1,221 +0,0 @@
|
||||
# Bark TTS Integration Guide
|
||||
|
||||
## Overview
|
||||
|
||||
OpenCCB now integrates with **Suno AI's Bark** text-to-speech system for generating audio versions of questions. This allows students to listen to questions instead of just reading them, improving accessibility and supporting different learning styles.
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
┌─────────────────┐ HTTP ┌─────────────────┐
|
||||
│ OpenCCB CMS │ ────────────> │ Bark TTS API │
|
||||
│ (PostgreSQL) │ <──────────── │ (Server t-800)│
|
||||
│ │ Audio │ │
|
||||
└─────────────────┘ └─────────────────┘
|
||||
```
|
||||
|
||||
## Deployment to t-800 Server
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- SSH access to t-800 server
|
||||
- At least 8GB RAM recommended (Bark loads large models)
|
||||
- 10GB free disk space
|
||||
- Python 3.8+
|
||||
- GPU optional (CUDA support for faster generation)
|
||||
|
||||
### Quick Deploy
|
||||
|
||||
```bash
|
||||
# From your local machine
|
||||
cd /home/juan/dev/openccb
|
||||
./scripts/deploy_to_t800.sh
|
||||
```
|
||||
|
||||
This will:
|
||||
1. SSH into t-800
|
||||
2. Install Python dependencies
|
||||
3. Clone Bark repository
|
||||
4. Set up systemd service
|
||||
5. Start the API server
|
||||
|
||||
### Manual Deploy
|
||||
|
||||
```bash
|
||||
# SSH into t-800
|
||||
ssh juan@t-800
|
||||
|
||||
# Run installation script
|
||||
wget https://raw.githubusercontent.com/suno-ai/bark/main/scripts/install.sh
|
||||
sudo bash install.sh
|
||||
```
|
||||
|
||||
## API Endpoints
|
||||
|
||||
Once deployed, Bark API is available at `http://t-800:8000`
|
||||
|
||||
### Health Check
|
||||
```bash
|
||||
curl http://t-800:8000/health
|
||||
```
|
||||
|
||||
### List Available Voices
|
||||
```bash
|
||||
curl http://t-800:8000/api/voices
|
||||
```
|
||||
|
||||
### Generate Speech
|
||||
```bash
|
||||
# Basic usage
|
||||
curl "http://t-800:8000/api/generate?text=What%20color%20is%20the%20sky%3F" \
|
||||
-o question.wav
|
||||
|
||||
# With specific voice and speed
|
||||
curl "http://t-800:8000/api/generate?text=Hello%20World&voice=v2/en_speaker_6&speed=1.2" \
|
||||
-o greeting.wav
|
||||
|
||||
# Spanish voice
|
||||
curl "http://t-800:8000/api/generate?text=Hola%20mundo&voice=v2/es_speaker_0" \
|
||||
-o saludo.wav
|
||||
```
|
||||
|
||||
## Available Voices
|
||||
|
||||
### English Voices
|
||||
- `v2/en_speaker_0` through `v2/en_speaker_9`
|
||||
|
||||
### Spanish Voices
|
||||
- `v2/es_speaker_0` through `v2/es_speaker_9`
|
||||
|
||||
## Integration with OpenCCB
|
||||
|
||||
### Generate Audio for a Question
|
||||
|
||||
```bash
|
||||
# Via API
|
||||
curl -X POST "http://localhost:3001/question-bank/{question_id}/generate-audio" \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"text": "What color is the sky?",
|
||||
"voice": "v2/en_speaker_1",
|
||||
"speed": 1.0
|
||||
}'
|
||||
```
|
||||
|
||||
### Automatic Audio Generation
|
||||
|
||||
When creating a question:
|
||||
|
||||
```json
|
||||
POST /question-bank
|
||||
{
|
||||
"question_text": "What is the capital of France?",
|
||||
"question_type": "multiple-choice",
|
||||
"options": ["Paris", "London", "Berlin", "Madrid"],
|
||||
"correct_answer": 0,
|
||||
"explanation": "Paris is the capital of France.",
|
||||
"generate_audio": true // Triggers async audio generation
|
||||
}
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
### Environment Variables
|
||||
|
||||
Add to your `.env` file:
|
||||
|
||||
```bash
|
||||
# Bark TTS API URL
|
||||
BARK_API_URL=http://t-800:8000
|
||||
|
||||
# Optional: Default voice for audio generation
|
||||
BARK_DEFAULT_VOICE=v2/en_speaker_1
|
||||
|
||||
# Optional: Default speed
|
||||
BARK_DEFAULT_SPEED=1.0
|
||||
```
|
||||
|
||||
## Performance Optimization
|
||||
|
||||
### Model Preloading
|
||||
|
||||
Bark preloads models on startup (takes ~30 seconds). The systemd service handles this automatically.
|
||||
|
||||
### Memory Management
|
||||
|
||||
The systemd service includes memory limits:
|
||||
```ini
|
||||
MemoryMax=4G
|
||||
MemoryHigh=3G
|
||||
```
|
||||
|
||||
Adjust based on your server's capacity.
|
||||
|
||||
### Batch Generation
|
||||
|
||||
For importing many questions:
|
||||
|
||||
```bash
|
||||
# Generate audio for multiple questions
|
||||
curl "http://t-800:8000/api/generate/batch?texts=Question%201&texts=Question%202&voice=v2/en_speaker_1"
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Service Not Starting
|
||||
|
||||
```bash
|
||||
# Check status
|
||||
sudo systemctl status bark-tts
|
||||
|
||||
# View logs
|
||||
sudo journalctl -u bark-tts -f
|
||||
|
||||
# Restart service
|
||||
sudo systemctl restart bark-tts
|
||||
```
|
||||
|
||||
### Out of Memory
|
||||
|
||||
If Bark crashes due to memory:
|
||||
1. Reduce `MemoryMax` in systemd service
|
||||
2. Use smaller models: `suno/bark-small`
|
||||
3. Process questions one at a time
|
||||
|
||||
### Slow Generation
|
||||
|
||||
- GPU acceleration: Install CUDA-enabled PyTorch
|
||||
- Reduce audio quality settings
|
||||
- Use shorter text segments
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
# Test English voice
|
||||
curl "http://t-800:8000/api/generate?text=The%20quick%20brown%20fox&voice=v2/en_speaker_1" | play -
|
||||
|
||||
# Test Spanish voice
|
||||
curl "http://t-800:8000/api/generate?text=El%20rápido%20zorro%20marrón&voice=v2/es_speaker_0" | play -
|
||||
```
|
||||
|
||||
## Security Notes
|
||||
|
||||
- Bark API runs on internal network only
|
||||
- No authentication required (assumes trusted network)
|
||||
- Rate limiting handled by OpenCCB
|
||||
- Audio files stored in `uploads/audio/` directory
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
- [ ] Add authentication to Bark API
|
||||
- [ ] Support for custom voice cloning
|
||||
- [ ] Audio preprocessing (noise reduction, normalization)
|
||||
- [ ] Caching layer for repeated requests
|
||||
- [ ] WebSocket support for streaming audio
|
||||
|
||||
## References
|
||||
|
||||
- [Bark GitHub](https://github.com/suno-ai/bark)
|
||||
- [Bark Hugging Face](https://huggingface.co/suno/bark)
|
||||
- [OpenCCB Question Bank Documentation](../docs/question-bank.md)
|
||||
@@ -101,40 +101,6 @@ Modal para importar preguntas desde MySQL:
|
||||
- Progreso de importación
|
||||
- Resultado (éxito/error)
|
||||
|
||||
### 5. AudioGeneratorModal (`AudioGeneratorModal.tsx`)
|
||||
|
||||
Modal para generar audio con Bark TTS:
|
||||
|
||||
**Configuración:**
|
||||
- Vista previa del texto de la pregunta
|
||||
- Texto personalizable (opcional)
|
||||
- Selector de voz (6 opciones: 3 inglés, 3 español)
|
||||
- Control de velocidad (0.5x - 2.0x)
|
||||
|
||||
**Voces disponibles:**
|
||||
```
|
||||
Inglés:
|
||||
- v2/en_speaker_0 (English Speaker 0)
|
||||
- v2/en_speaker_1 (English Speaker 1) ← default
|
||||
- v2/en_speaker_6 (English Speaker 6)
|
||||
|
||||
Español:
|
||||
- v2/es_speaker_0 (Spanish Speaker 0)
|
||||
- v2/es_speaker_1 (Spanish Speaker 1)
|
||||
- v2/es_speaker_3 (Spanish Speaker 3)
|
||||
```
|
||||
|
||||
**Estados:**
|
||||
- ⏳ Generando... (polling cada 1s, max 30s)
|
||||
- ✅ Audio generado (con preview play/pause)
|
||||
- ❌ Error (mensaje descriptivo)
|
||||
|
||||
**Características:**
|
||||
- Polling automático para verificar estado
|
||||
- Reproductor de audio integrado
|
||||
- Botón Play/Pause
|
||||
- Indicador visual de estado
|
||||
|
||||
## Flujos de Usuario
|
||||
|
||||
### Crear Pregunta Manualmente
|
||||
@@ -288,11 +254,6 @@ GET /question-bank/mysql-courses
|
||||
- Verificar que `MYSQL_DATABASE_URL` esté configurado en `.env`
|
||||
- Verificar conectividad al servidor MySQL
|
||||
|
||||
**Error: "Error al generar audio"**
|
||||
- Verificar que Bark TTS esté corriendo en t-800
|
||||
- Verificar que `BARK_API_URL` esté configurado
|
||||
- Revisar logs de Bark: `ssh juan@t-800 && journalctl -u bark-tts -f`
|
||||
|
||||
**Audio no se reproduce**
|
||||
- Verificar formato de audio (WAV soportado)
|
||||
- Verificar permisos del navegador
|
||||
@@ -301,5 +262,4 @@ GET /question-bank/mysql-courses
|
||||
## Referencias
|
||||
|
||||
- [Question Bank Backend](../../services/cms-service/src/handlers_question_bank.rs)
|
||||
- [Bark TTS Guide](../../docs/BARK_TTS_GUIDE.md)
|
||||
- [Test Templates UI](./TestTemplates/)
|
||||
|
||||
Reference in New Issue
Block a user