forked from deepgram-devs/BackgroundFiltering
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_demo.py
More file actions
executable file
Β·212 lines (173 loc) Β· 6.62 KB
/
Copy pathsetup_demo.py
File metadata and controls
executable file
Β·212 lines (173 loc) Β· 6.62 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env python3
"""
Voice Filter - Demo Setup Script
Quick setup for the voice diarization and filtering demo
"""
import os
import sys
import subprocess
from pathlib import Path
def print_header():
"""Print demo setup header"""
print("=" * 60)
print("π― VOICE FILTER - Demo Setup")
print("=" * 60)
print("π€ Speaker Diarization & Voice Filtering Demo")
print("π Focus on voice locking and filtering technology")
print("π¨ Deepgram-inspired interface")
print("=" * 60)
print()
def check_python_version():
"""Check if Python version is compatible"""
print("π Checking Python version...")
if sys.version_info < (3, 7):
print("β Python 3.7+ required. Please upgrade Python.")
return False
print(f"β
Python {sys.version_info.major}.{sys.version_info.minor} detected")
return True
def install_dependencies():
"""Install required dependencies"""
print("\nπ¦ Installing dependencies...")
requirements_file = Path("requirements.txt")
if not requirements_file.exists():
print("β requirements.txt not found!")
print("Please ensure requirements.txt is in the current directory.")
return False
try:
# Install dependencies
result = subprocess.run([
sys.executable, "-m", "pip", "install", "-r", "requirements.txt"
], capture_output=True, text=True, check=True)
print("β
Dependencies installed successfully!")
return True
except subprocess.CalledProcessError as e:
print(f"β Error installing dependencies: {e}")
print("Error output:")
print(e.stderr)
return False
def check_env_file():
"""Check if .env file exists and help create it"""
print("\nπ Checking environment configuration...")
env_file = Path(".env")
if env_file.exists():
print("β
.env file found")
# Check if it has the required key
try:
with open(env_file, 'r') as f:
content = f.read()
if "DEEPGRAM_API_KEY" in content and not content.find("your_deepgram_api_key_here"):
print("β
Deepgram API key appears to be configured")
return True
else:
print("β οΈ .env file exists but API key may not be set properly")
except Exception as e:
print(f"β οΈ Error reading .env file: {e}")
print("β .env file missing or incomplete")
print("\nπ Creating .env file...")
# Create .env file
env_content = """# Voice Filter Configuration
# Get your API key from: https://console.deepgram.com/
DEEPGRAM_API_KEY=your_deepgram_api_key_here
"""
try:
with open(".env", "w") as f:
f.write(env_content)
print("β
.env file created!")
print("\nπ§ IMPORTANT: Edit .env file and add your Deepgram API key")
print(" 1. Visit: https://console.deepgram.com/")
print(" 2. Create account (free credits available)")
print(" 3. Copy your API key")
print(" 4. Replace 'your_deepgram_api_key_here' in .env file")
return False # Return False because user needs to add API key
except Exception as e:
print(f"β Error creating .env file: {e}")
return False
def test_audio():
"""Test if audio system is working"""
print("\nπ€ Testing audio system...")
try:
import pyaudio
# Try to initialize PyAudio
p = pyaudio.PyAudio()
# Check for input devices
device_count = p.get_device_count()
input_devices = []
for i in range(device_count):
device_info = p.get_device_info_by_index(i)
if device_info['maxInputChannels'] > 0:
input_devices.append(device_info['name'])
p.terminate()
if input_devices:
print(f"β
Audio system working! Found {len(input_devices)} input device(s)")
print(f" Default input device: {input_devices[0]}")
return True
else:
print("β No audio input devices found")
return False
except ImportError:
print("β οΈ PyAudio not installed - will be installed with dependencies")
return True
except Exception as e:
print(f"β οΈ Audio system warning: {e}")
return True
def check_demo_file():
"""Check if main demo file exists"""
print("\nπ Checking demo files...")
demo_file = Path("voice_filter.py")
if demo_file.exists():
print("β
Voice Filter demo file found")
return True
else:
print("β voice_filter.py not found!")
print("Please ensure voice_filter.py is in the current directory.")
return False
def print_next_steps(api_key_needed=False):
"""Print next steps for user"""
print("\n" + "=" * 60)
print("π― SETUP COMPLETE - Next Steps:")
print("=" * 60)
if api_key_needed:
print("1. π Add your Deepgram API key to .env file:")
print(" - Visit https://console.deepgram.com/")
print(" - Create account (free credits available)")
print(" - Copy API key and paste into .env file")
print()
print("2. π Run the demo:")
print(" python voice_filter.py")
else:
print("π Ready to run! Start the demo with:")
print(" python voice_filter.py")
print("\nπ€ Demo Features:")
print(" - Real-time speaker diarization")
print(" - Voice locking (first speaker)")
print(" - Live filtering of other voices")
print(" - Terminal showing filtering activity")
print(" - Deepgram-inspired interface")
print("\nπ§ Usage Tips:")
print(" - Speak clearly for best results")
print(" - First person to speak gets voice lock")
print(" - Use 'Reset Speaker Lock' to change speakers")
print(" - Say 'exit filter' to stop demo")
print("\n" + "=" * 60)
def main():
"""Main setup function"""
print_header()
# Step 1: Check Python version
if not check_python_version():
return 1
# Step 2: Check demo file exists
if not check_demo_file():
return 1
# Step 3: Install dependencies
if not install_dependencies():
return 1
# Step 4: Test audio system
test_audio()
# Step 5: Check/create .env file
api_key_needed = not check_env_file()
# Step 6: Show next steps
print_next_steps(api_key_needed)
return 0
if __name__ == "__main__":
exit_code = main()
sys.exit(exit_code)