Spaces:
Running
Running
File size: 2,967 Bytes
f5bce42 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #!/usr/bin/env python3
"""Basic test script for the SRT Caption Generator modules."""
import tempfile
from pathlib import Path
from validator import validate_inputs
from normalize import normalize_audio
from srt_writer import write_srt
def test_basic_functionality():
"""Test basic functionality without requiring alignment model."""
print("🧪 Testing SRT Caption Generator modules...")
# Test files
input_dir = Path("input")
test_audio = input_dir / "test_audio.wav"
test_script = input_dir / "test_script.txt"
if not test_audio.exists():
print("❌ Test audio file not found. Run: ffmpeg -f lavfi -i \"sine=frequency=440:duration=3\" -ar 16000 -ac 1 input/test_audio.wav")
return False
if not test_script.exists():
print("❌ Test script file not found")
return False
try:
# Test 1: Validation
print(" Testing validator...")
result = validate_inputs(test_audio, test_script)
print(f" ✅ Validation: {result['audio_duration_sec']:.1f}s, {result['sentence_count']} sentences")
# Test 2: Audio normalization
print(" Testing audio normalization...")
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
temp_path = tmp.name
normalized_path = normalize_audio(test_audio, temp_path)
print(f" ✅ Normalization: {Path(normalized_path).name}")
# Test 3: SRT writing (with dummy data)
print(" Testing SRT writer...")
test_segments = [
{
"index": 1,
"text": "هذا اختبار للنظام",
"start_ms": 0,
"end_ms": 1000
},
{
"index": 2,
"text": "This is a system test",
"start_ms": 1050,
"end_ms": 2000
},
{
"index": 3,
"text": "C'est un test du système",
"start_ms": 2050,
"end_ms": 3000
}
]
output_dir = Path("output")
output_dir.mkdir(exist_ok=True)
srt_path = write_srt(test_segments, output_dir / "test_output.srt")
print(f" ✅ SRT generation: {Path(srt_path).name}")
# Cleanup
Path(temp_path).unlink(missing_ok=True)
print("\n🎉 Basic functionality tests passed!")
print("🔧 To test full alignment pipeline:")
print(" 1. Install: pip install ctc-forced-aligner torch torchaudio")
print(" 2. Run: python3 align.py --audio input/test_audio.wav --script input/test_script.txt")
return True
except Exception as e:
print(f"❌ Test failed: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
test_basic_functionality() |