-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoice_control.py
More file actions
59 lines (49 loc) · 1.78 KB
/
Copy pathvoice_control.py
File metadata and controls
59 lines (49 loc) · 1.78 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
import win32com.client
import time
import speech_recognition as sr
# === Setup PowerPoint Application ===
ppt_app = win32com.client.Dispatch("PowerPoint.Application")
ppt_app.Visible = True # Make PowerPoint visible
# === Open Your Presentation ===
presentation_path = r"C:\Users\lenovo\Downloads\hackindia ppt .pptx" # <-- Replace this
presentation = ppt_app.Presentations.Open(presentation_path)
# === Start Slide Show ===
slideshow = presentation.SlideShowSettings.Run()
# === Setup Voice Recognition ===
recognizer = sr.Recognizer()
mic = sr.Microphone()
# === Define Commands ===
commands = {
"next": lambda: slideshow.View.Next(),
"previous": lambda: slideshow.View.Previous(),
"end": lambda: presentation.SlideShowWindow.View.Exit()
}
print("\n🎤 Voice control started...")
print("Say 'next', 'previous', or 'end' to control the presentation.")
try:
while True:
with mic as source:
recognizer.adjust_for_ambient_noise(source)
print("\n🎧 Listening...")
audio = recognizer.listen(source)
try:
command = recognizer.recognize_google(audio).lower()
print("✅ You said:", command)
if command in commands:
commands[command]()
print(f"✅ Executed: {command}")
if command == "end":
break
else:
print("❌ Unknown command. Try: next, previous, or end.")
except sr.UnknownValueError:
print("❗ Could not understand audio.")
except sr.RequestError as e:
print(f"❗ Could not request results; {e}")
except KeyboardInterrupt:
print("🛑 Exiting on user interrupt.")
# === Cleanup ===
time.sleep(1)
presentation.Close()
ppt_app.Quit()
print("👋 PowerPoint closed.")