File size: 3,193 Bytes
7fcb2a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3
"""Test script to verify pre-downloading XTTS model and using local path."""

import os
import sys
from pathlib import Path

# Set env vars BEFORE TTS import - ALL of them needed to suppress prompts
os.environ['TTS_HOME'] = str(Path('E:/tmp/tts_models').absolute())
os.environ['TTS_CPML'] = '1'
os.environ['TTS_SKIP_TOS'] = '1'
os.environ['TTS_DISABLE_WEB_VERSION_PROMPT'] = '1'
os.environ['COQUI_TOS_AGREED'] = '1'

# Also try monkey-patching input to auto-answer
import builtins
original_input = builtins.input

def auto_input(prompt=""):
    print(prompt + "y")  # Print the prompt with auto-answer
    return "y"

builtins.input = auto_input

print("=" * 60)
print("XTTS Model Pre-Download Test")
print("=" * 60)

# Step 1: Download model to local path
print("\n[Step 1] Downloading XTTS model...")
try:
    from TTS.api import TTS
    
    # This will auto-download to TTS_HOME
    print("Initializing TTS (will auto-download model)...")
    model = TTS(
        model_name="tts_models/multilingual/multi-dataset/xtts_v2",
        gpu=False
    )
    print("βœ“ Model downloaded successfully!")
    
    # Find where it was downloaded
    tts_home = os.environ.get('TTS_HOME', os.path.expanduser('~/.tts_models'))
    model_path = Path(tts_home) / "tts_models--multilingual--multi-dataset--xtts_v2"
    
    if model_path.exists():
        print(f"βœ“ Model location: {model_path}")
        print(f"βœ“ Model files:")
        for item in sorted(model_path.iterdir()):
            print(f"  - {item.name}")
    
    # Step 2: Test loading from local path
    print("\n[Step 2] Testing local path loading...")
    del model  # Free memory
    
    # Try loading with explicit paths
    config_path = model_path / "config.json"
    
    if config_path.exists():
        print(f"βœ“ Config found at: {config_path}")
        print("\n[Step 3] Loading model from local path...")
        try:
            model2 = TTS(
                model_name="tts_models/multilingual/multi-dataset/xtts_v2",
                model_path=str(model_path),
                config_path=str(config_path),
                gpu=False
            )
            print("βœ“ Model loaded successfully from local path!")
            print("\n" + "=" * 60)
            print("SUCCESS: Pre-downloaded model loading works!")
            print("=" * 60)
        except Exception as e:
            print(f"βœ— Failed to load from local path: {e}")
            print("\nTrying fallback: Loading with just model_name...")
            model2 = TTS(
                model_name="tts_models/multilingual/multi-dataset/xtts_v2",
                gpu=False
            )
            print("βœ“ Fallback load successful (auto-download approach)")
    else:
        print(f"βœ— Config not found at {config_path}")
        print("Model structure:")
        for item in model_path.iterdir():
            print(f"  {item}")
            
except KeyboardInterrupt:
    print("\n\nβœ— Download interrupted by user")
    sys.exit(1)
except Exception as e:
    print(f"βœ— Error: {e}")
    import traceback
    traceback.print_exc()
    sys.exit(1)
finally:
    # Restore original input
    builtins.input = original_input