-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoice_demo.py
More file actions
executable file
·278 lines (238 loc) · 9.33 KB
/
voice_demo.py
File metadata and controls
executable file
·278 lines (238 loc) · 9.33 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/usr/bin/env python3
"""
Advanced Mini Bash - Voice Control Demo Script
Interactive demo showcasing Hindi and English voice commands
"""
import os
import sys
import time
import subprocess
from typing import List, Dict
class VoiceDemo:
def __init__(self):
"""Initialize the voice demo"""
self.demo_commands = {
"hindi": [
"फोल्डर खोलो",
"वर्तमान फोल्डर",
"सिस्टम जानकारी",
"समय दिखाओ",
"हिस्ट्री दिखाओ"
],
"english": [
"list files",
"current directory",
"system info",
"show time",
"show history"
]
}
self.expected_outputs = {
"फोल्डर खोलो": "ls",
"वर्तमान फोल्डर": "pwd",
"सिस्टम जानकारी": "uname -a",
"समय दिखाओ": "date",
"हिस्ट्री दिखाओ": "history",
"list files": "ls",
"current directory": "pwd",
"system info": "uname -a",
"show time": "date",
"show history": "history"
}
def print_banner(self):
"""Print demo banner"""
print("🔥" + "="*68 + "🔥")
print("🎤 Advanced Mini Bash - Voice Control Demo (Phase 3)")
print("🔥" + "="*68 + "🔥")
print()
print("🌟 Features Demonstrated:")
print(" • Hindi Voice Commands (हिंदी आवाज़ कमांड)")
print(" • English Voice Commands")
print(" • Google Cloud Speech-to-Text")
print(" • Google Cloud Translation")
print(" • Google Cloud Text-to-Speech")
print(" • Real-time Command Execution")
print()
def check_dependencies(self) -> bool:
"""Check if all dependencies are available"""
print("🔍 Checking dependencies...")
# Check Mini Bash
if not os.path.exists("./mini-bash"):
print("❌ Mini Bash not found! Run 'make' first.")
return False
print("✅ Mini Bash found")
# Check Google Cloud credentials
if not os.path.exists("credentials.json"):
print("❌ Google Cloud credentials not found!")
print(" Please place credentials.json in current directory")
return False
print("✅ Google Cloud credentials found")
# Check Python modules
try:
import google.cloud.speech
import google.cloud.translate_v2
import google.cloud.texttospeech
import pyaudio
print("✅ Google Cloud libraries found")
except ImportError as e:
print(f"❌ Missing Python libraries: {e}")
print(" Run: pip install -r requirements.txt")
return False
return True
def show_voice_commands(self):
"""Show available voice commands"""
print("🎤 Available Voice Commands:")
print()
print("🇮🇳 Hindi Commands (हिंदी):")
for i, cmd in enumerate(self.demo_commands["hindi"], 1):
print(f" {i}. \"{cmd}\" → {self.expected_outputs[cmd]}")
print()
print("🇺🇸 English Commands:")
for i, cmd in enumerate(self.demo_commands["english"], 1):
print(f" {i}. \"{cmd}\" → {self.expected_outputs[cmd]}")
print()
def run_interactive_demo(self):
"""Run interactive demo"""
print("🎮 Interactive Demo Mode")
print("=" * 30)
print()
print("Choose an option:")
print("1. 🎤 Start Voice Control (Real-time)")
print("2. 🧪 Test Commands (Simulated)")
print("3. 📚 Show Command Examples")
print("4. ❌ Exit")
print()
while True:
try:
choice = input("Enter your choice (1-4): ").strip()
if choice == "1":
self.start_voice_control()
break
elif choice == "2":
self.run_simulated_demo()
break
elif choice == "3":
self.show_voice_commands()
continue
elif choice == "4":
print("👋 Goodbye!")
break
else:
print("❌ Invalid choice. Please enter 1-4.")
except KeyboardInterrupt:
print("\n👋 Goodbye!")
break
def start_voice_control(self):
"""Start real voice control"""
print("🎤 Starting Voice Control...")
print("Make sure your microphone is working!")
print("Press Ctrl+C to stop")
print()
try:
# Import and run the enhanced voice module
from voice_enhanced import EnhancedVoiceShell
voice_shell = EnhancedVoiceShell()
voice_shell.run()
except ImportError:
print("❌ Voice module not found!")
print("Make sure voice_enhanced.py is in the current directory")
except Exception as e:
print(f"❌ Error starting voice control: {e}")
def run_simulated_demo(self):
"""Run simulated demo without actual voice input"""
print("🧪 Simulated Demo Mode")
print("=" * 25)
print()
print("This will simulate voice commands without using the microphone.")
print()
# Test Hindi commands
print("🇮🇳 Testing Hindi Commands:")
for cmd in self.demo_commands["hindi"]:
print(f"\n🎤 Simulated: \"{cmd}\"")
print(f"🔄 Mapped to: {self.expected_outputs[cmd]}")
# Execute the command
try:
result = subprocess.run(
["./mini-bash"],
input=f"{self.expected_outputs[cmd]}\nexit\n",
text=True,
capture_output=True,
timeout=5
)
if result.stdout:
print("📤 Output:")
print(result.stdout)
if result.stderr:
print("⚠️ Error:")
print(result.stderr)
except subprocess.TimeoutExpired:
print("⏰ Command timed out")
except Exception as e:
print(f"❌ Error: {e}")
time.sleep(1)
print("\n" + "="*50)
# Test English commands
print("🇺🇸 Testing English Commands:")
for cmd in self.demo_commands["english"]:
print(f"\n🎤 Simulated: \"{cmd}\"")
print(f"🔄 Mapped to: {self.expected_outputs[cmd]}")
# Execute the command
try:
result = subprocess.run(
["./mini-bash"],
input=f"{self.expected_outputs[cmd]}\nexit\n",
text=True,
capture_output=True,
timeout=5
)
if result.stdout:
print("📤 Output:")
print(result.stdout)
if result.stderr:
print("⚠️ Error:")
print(result.stderr)
except subprocess.TimeoutExpired:
print("⏰ Command timed out")
except Exception as e:
print(f"❌ Error: {e}")
time.sleep(1)
print("\n✅ Simulated demo completed!")
def show_setup_instructions(self):
"""Show setup instructions"""
print("📋 Setup Instructions:")
print("=" * 25)
print()
print("1. 🔧 Install Dependencies:")
print(" pip install -r requirements.txt")
print()
print("2. 🔑 Get Google Cloud Credentials:")
print(" • Go to: https://console.cloud.google.com/apis/credentials")
print(" • Create a service account")
print(" • Download JSON key file")
print(" • Rename to 'credentials.json'")
print()
print("3. 🎤 Test Microphone:")
print(" • Make sure your microphone is working")
print(" • Test with: python3 test_voice.py")
print()
print("4. 🚀 Run Voice Control:")
print(" • python3 voice_enhanced.py")
print(" • Or: python3 voice_demo.py")
print()
def run(self):
"""Run the complete demo"""
self.print_banner()
if not self.check_dependencies():
print("\n❌ Dependencies check failed!")
self.show_setup_instructions()
return
print("✅ All dependencies ready!")
print()
self.show_voice_commands()
self.run_interactive_demo()
def main():
"""Main entry point"""
demo = VoiceDemo()
demo.run()
if __name__ == "__main__":
main()