- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
Latest commit
79 lines (63 loc) · 2.7 KB
/
Copy pathmain.py
File metadata and controls
79 lines (63 loc) · 2.7 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
importspeech_recognitionassr
importwebbrowser
importmusicLibrary
importsubprocess
importrequests
r=sr.Recognizer()
newsapi="6eee54148e914e1485fc550a05d28e1a"
# Working TTS function (Method 1 - PowerShell)
defspeak_old(text):
print(f"Speaking: {text}")
try:
cmd=f'powershell -Command "Add-Type -AssemblyName System.Speech; $speak_old = New-Object System.Speech.Synthesis.SpeechSynthesizer; $speak_old.Speak(\'{text}\')"'
subprocess.run(cmd, shell=True, capture_output=True)
exceptExceptionase:
print(f"TTS failed: {e}")
defprocessCommand(c):
if"open google"inc.lower():
webbrowser.open("https://google.com")
elif"open facebook"inc.lower():
webbrowser.open("https://facebook.com")
elif"open youtube"inc.lower():
webbrowser.open("https://youtube.com")
elif"open linkedin"inc.lower():
webbrowser.open("https://linkedin.com")
elif"open chat"inc.lower():
webbrowser.open("https://web.whatsapp.com")
elifc.lower().startswith("play"):
song=c.lower().split(" ")[1]
link=musicLibrary.music[song]
webbrowser.open(link)
elif"news"inc.lower():
r=requests.get("https://newsapi.org/v2/top-headlines?country=us&apiKey=6eee54148e914e1485fc550a05d28e1a")
ifr.status_code==200:
data=r.json()
print(data) # <-- yeh add karo dekhne ke liye kya aa raha hai
articles=data.get('articles', [])
ifnotarticles:
speak_old("No news articles found.")
else:
forarticleinarticles[:5]: # Sirf 5 headlines sunaye
speak_old(article['title'])
else:
speak_old("Failed to fetch news.")
if__name__=="__main__":
speak_old("Initializing Jarvis....")
whileTrue:
# listen for the jarvis
r=sr.Recognizer()
try:
withsr.Microphone() assource:
print("listening.....")
audio=r.listen(source, timeout=5, phrase_time_limit=3)
word=r.recognize_google(audio)
print(f"Recognized: {word}")
if(word.lower() =="jarvis"):
speak_old("ya")
withsr.Microphone() assource:
print("Jarvis Active")
audio=r.listen(source)
command=r.recognize_google(audio)
processCommand(command)
exceptExceptionase:
print("Error: {0}".format(e))