File size: 1,722 Bytes
383520d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Scheduled tasks for the TTS API."""
import asyncio
import logging
import time
from datetime import datetime

logger = logging.getLogger(__name__)

async def periodic_voice_profile_backup(app_state, interval_hours=6):
    """
    Periodically save voice profiles to persistent storage.
    
    Args:
        app_state: The application state object
        interval_hours: Backup interval in hours
    """
    while True:
        try:
            # Wait for the specified interval
            await asyncio.sleep(interval_hours * 3600)
            
            # Log the backup
            timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            logger.info(f"Scheduled voice profile backup started at {timestamp}")
            
            # Save voice profiles
            if hasattr(app_state, "voice_enhancement_enabled") and app_state.voice_enhancement_enabled:
                from app.voice_enhancement import save_voice_profiles
                save_voice_profiles()
                logger.info("Voice profiles saved successfully")
                
            # Save voice memories
            if hasattr(app_state, "voice_memory_enabled") and app_state.voice_memory_enabled:
                for voice_name in app_state.voice_cache:
                    if voice_name in ["alloy", "echo", "fable", "onyx", "nova", "shimmer"]:
                        from app.voice_memory import VOICE_MEMORIES
                        if voice_name in VOICE_MEMORIES:
                            VOICE_MEMORIES[voice_name].save()
                logger.info("Voice memories saved successfully")
                
        except Exception as e:
            logger.error(f"Error in periodic voice profile backup: {e}")