-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeech.py
More file actions
48 lines (40 loc) · 1.62 KB
/
speech.py
File metadata and controls
48 lines (40 loc) · 1.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
import os
import speech_recognition as sr
import pyttsx3
import webbrowser
# Initialize speech recognizer and text-to-speech engine
recognizer = sr.Recognizer()
engine = pyttsx3.init()
# Function to speak text
def speak(text):
engine.say(text)
engine.runAndWait()
# Main loop
speak("JAY SHRI RAM, AND LETS TALK")
while True:
try:
r=sr.Recognizer()
# Use microphone as audio source
with sr.Microphone() as source:
r.pause_threshold=0.5
print("Listening...")
audio = recognizer.listen(source)
# Recognize speech using Google Speech Recognition
text = recognizer.recognize_google(audio)
print("You said:", text)
#speak(text)
#opening website
sites=[["youtube","https://www.youtube.com"],["wikipedia",'https://www.wikipedia.com'],["google",'https://www.google.com']]
for site in sites:
if f"Open {site[0]}".lower() in text.lower():
speak(f"opening {site[0]}")
webbrowser.open(site[1])
#todo: chage here to open any movie/song
if "open movie".lower() in text.lower():
movie="C:/Users/nsubh/Downloads/EP.18.v0.1639649397.720p.mp4"
os.startfile(movie)
# Example: Basic response (you can customize this)
except sr.UnknownValueError:
print("Could not understand audio, please repeat")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))