#!/usr/bin/env python3 import sys sys.path.insert(0, 'backend') import asyncio from services.role_detector import RoleDetector from services.tts_service import TTSService from services.ollama_service import OllamaService async def test(): # Read the actual story with open('Test Story.txt', 'r') as f: story = f.read() print(f'Story length: {len(story)} characters\n') # Initialize services ollama_service = OllamaService() role_detector = RoleDetector(ollama_service=ollama_service) tts_service = TTSService(ollama_service=ollama_service) # Step 1: Detect roles print('Step 1: Detecting roles...') roles = await role_detector.detect_roles(story) print(f'Detected {len(roles)} roles: {[r["label"] for r in roles]}\n') # Step 2: Assign voices print('Step 2: Assigning voices...') role_voice_map = { 'Lily': 'af_bella', 'Benny': 'am_adam', 'Sammy': 'am_michael', 'Narrator': 'af_sarah' } for role, voice in role_voice_map.items(): print(f' {role} → {voice}') print() # Step 3: Test AI segmentation print('Step 3: Testing AI segmentation...') segments = await tts_service.segment_text_with_ai(story, role_voice_map) if segments is None: print('❌ AI segmentation returned None!') print('Falling back to pattern-based segmentation...') segments = tts_service.segment_text(story, role_voice_map) print(f'Generated {len(segments)} segments\n') # Analyze segments speaker_counts = {} for speaker, voice, text in segments: speaker_counts[speaker] = speaker_counts.get(speaker, 0) + 1 print('Segments per speaker:') for speaker, count in sorted(speaker_counts.items(), key=lambda x: x[1], reverse=True): print(f' {speaker}: {count} segments') print('\nFirst 5 segments:') for i, (speaker, voice, text) in enumerate(segments[:5], 1): preview = text[:80] + '...' if len(text) > 80 else text print(f' {i}. [{speaker}] {preview}') asyncio.run(test())