AJ50 commited on
Commit
7fcb2a7
Β·
1 Parent(s): aeb26b6

Suppress TTS interactive prompts: Monkey-patch input() to auto-answer 'y' + set all TOS env vars

Browse files
backend/app/multilingual_tts.py CHANGED
@@ -2,12 +2,24 @@
2
 
3
  import os
4
  import sys
 
5
 
6
- # Set environment variables BEFORE any TTS imports to bypass CPML prompt
7
  os.environ['TTS_HOME'] = '/tmp/tts_models'
8
- os.environ['TTS_CPML'] = '1' # Auto-accept CPML license for non-commercial use
9
- # Disable interactive prompts completely
10
  os.environ['TTS_SKIP_TOS'] = '1'
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  import gc
13
  import torch
 
2
 
3
  import os
4
  import sys
5
+ import builtins
6
 
7
+ # CRITICAL: Suppress TTS interactive prompts BEFORE any imports
8
  os.environ['TTS_HOME'] = '/tmp/tts_models'
9
+ os.environ['TTS_CPML'] = '1'
 
10
  os.environ['TTS_SKIP_TOS'] = '1'
11
+ os.environ['TTS_DISABLE_WEB_VERSION_PROMPT'] = '1'
12
+ os.environ['COQUI_TOS_AGREED'] = '1'
13
+
14
+ # Monkey-patch input() to auto-answer prompts non-interactively
15
+ _original_input = builtins.input
16
+ def _auto_input(prompt=""):
17
+ """Auto-answer 'y' to all prompts without blocking."""
18
+ sys.stderr.write(prompt + "y\n")
19
+ sys.stderr.flush()
20
+ return "y"
21
+
22
+ builtins.input = _auto_input
23
 
24
  import gc
25
  import torch
test_xtts_download.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Test script to verify pre-downloading XTTS model and using local path."""
3
+
4
+ import os
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ # Set env vars BEFORE TTS import - ALL of them needed to suppress prompts
9
+ os.environ['TTS_HOME'] = str(Path('E:/tmp/tts_models').absolute())
10
+ os.environ['TTS_CPML'] = '1'
11
+ os.environ['TTS_SKIP_TOS'] = '1'
12
+ os.environ['TTS_DISABLE_WEB_VERSION_PROMPT'] = '1'
13
+ os.environ['COQUI_TOS_AGREED'] = '1'
14
+
15
+ # Also try monkey-patching input to auto-answer
16
+ import builtins
17
+ original_input = builtins.input
18
+
19
+ def auto_input(prompt=""):
20
+ print(prompt + "y") # Print the prompt with auto-answer
21
+ return "y"
22
+
23
+ builtins.input = auto_input
24
+
25
+ print("=" * 60)
26
+ print("XTTS Model Pre-Download Test")
27
+ print("=" * 60)
28
+
29
+ # Step 1: Download model to local path
30
+ print("\n[Step 1] Downloading XTTS model...")
31
+ try:
32
+ from TTS.api import TTS
33
+
34
+ # This will auto-download to TTS_HOME
35
+ print("Initializing TTS (will auto-download model)...")
36
+ model = TTS(
37
+ model_name="tts_models/multilingual/multi-dataset/xtts_v2",
38
+ gpu=False
39
+ )
40
+ print("βœ“ Model downloaded successfully!")
41
+
42
+ # Find where it was downloaded
43
+ tts_home = os.environ.get('TTS_HOME', os.path.expanduser('~/.tts_models'))
44
+ model_path = Path(tts_home) / "tts_models--multilingual--multi-dataset--xtts_v2"
45
+
46
+ if model_path.exists():
47
+ print(f"βœ“ Model location: {model_path}")
48
+ print(f"βœ“ Model files:")
49
+ for item in sorted(model_path.iterdir()):
50
+ print(f" - {item.name}")
51
+
52
+ # Step 2: Test loading from local path
53
+ print("\n[Step 2] Testing local path loading...")
54
+ del model # Free memory
55
+
56
+ # Try loading with explicit paths
57
+ config_path = model_path / "config.json"
58
+
59
+ if config_path.exists():
60
+ print(f"βœ“ Config found at: {config_path}")
61
+ print("\n[Step 3] Loading model from local path...")
62
+ try:
63
+ model2 = TTS(
64
+ model_name="tts_models/multilingual/multi-dataset/xtts_v2",
65
+ model_path=str(model_path),
66
+ config_path=str(config_path),
67
+ gpu=False
68
+ )
69
+ print("βœ“ Model loaded successfully from local path!")
70
+ print("\n" + "=" * 60)
71
+ print("SUCCESS: Pre-downloaded model loading works!")
72
+ print("=" * 60)
73
+ except Exception as e:
74
+ print(f"βœ— Failed to load from local path: {e}")
75
+ print("\nTrying fallback: Loading with just model_name...")
76
+ model2 = TTS(
77
+ model_name="tts_models/multilingual/multi-dataset/xtts_v2",
78
+ gpu=False
79
+ )
80
+ print("βœ“ Fallback load successful (auto-download approach)")
81
+ else:
82
+ print(f"βœ— Config not found at {config_path}")
83
+ print("Model structure:")
84
+ for item in model_path.iterdir():
85
+ print(f" {item}")
86
+
87
+ except KeyboardInterrupt:
88
+ print("\n\nβœ— Download interrupted by user")
89
+ sys.exit(1)
90
+ except Exception as e:
91
+ print(f"βœ— Error: {e}")
92
+ import traceback
93
+ traceback.print_exc()
94
+ sys.exit(1)
95
+ finally:
96
+ # Restore original input
97
+ builtins.input = original_input
98
+