mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-23 20:11:10 +00:00
Merge pull request #38 from avyayjain/master
Create voice_activated_alarm.py
This commit is contained in:
commit
ba97c9955e
11
scripts/voice_activated_alaram/README.md
Normal file
11
scripts/voice_activated_alaram/README.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
voice activated alarm
|
||||
This project contains an AI powered voice activated alarms for pandas like me
|
||||
|
||||
you have to install
|
||||
|
||||
pyttsx3~=2.90
|
||||
wikipedia~=1.4.0
|
||||
pyjokes~=0.6.0
|
||||
pywhatkit~=5.4
|
||||
requests~=2.28.1
|
||||
beautifulsoup4~=4.11.1
|
76
scripts/voice_activated_alaram/voice_activated_alarm.py
Normal file
76
scripts/voice_activated_alaram/voice_activated_alarm.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
import datetime
|
||||
from pyttsx3 import engine
|
||||
import speech_recognition as sr
|
||||
import pyttsx3 as py
|
||||
import winsound
|
||||
|
||||
engine = py.init()
|
||||
|
||||
|
||||
def alarm(timing):
|
||||
alTime = str(datetime.datetime.now().strptime(timing, "%I:%M %p"))
|
||||
|
||||
alTime = alTime[11:-3]
|
||||
print(alTime)
|
||||
Horeal = alTime[:2]
|
||||
Horeal = int(Horeal)
|
||||
Mireal = alTime[3:5]
|
||||
Mireal = int(Mireal)
|
||||
|
||||
print(f"Done, alarm is set for {timing}")
|
||||
|
||||
while True:
|
||||
if Horeal == datetime.datetime.now().hour and Mireal == \
|
||||
datetime.datetime.now().minute:
|
||||
print("alarm is running")
|
||||
winsound.PlaySound('abc', winsound.SND_LOOP)
|
||||
|
||||
elif Mireal < datetime.datetime.now().minute:
|
||||
break
|
||||
|
||||
|
||||
def speech(audio):
|
||||
engine.setProperty('rate', 200)
|
||||
voices = engine.getProperty('voices')
|
||||
# engine.setProperty('voice', voices[1].id)
|
||||
engine.setProperty('voice', voices[0].id)
|
||||
engine.say(audio)
|
||||
engine.runAndWait()
|
||||
|
||||
|
||||
def takeCommand():
|
||||
# It takes microphone input from the user and returns string output
|
||||
|
||||
r = sr.Recognizer()
|
||||
with sr.Microphone() as source:
|
||||
r.adjust_for_ambient_noise(source, duration=1)
|
||||
print()
|
||||
print("Listening...")
|
||||
print()
|
||||
# r.pause_threshold = 1
|
||||
audio = r.listen(source)
|
||||
|
||||
try:
|
||||
print("Recognizing...")
|
||||
print()
|
||||
query = r.recognize_google(audio, language='en-in')
|
||||
print(f"you said: {query}\n")
|
||||
|
||||
except Exception as e:
|
||||
print("Say that again please...")
|
||||
print()
|
||||
print(e)
|
||||
return "None"
|
||||
return query
|
||||
|
||||
|
||||
speechinput = takeCommand().lower()
|
||||
|
||||
if 'alarm' in speechinput:
|
||||
speech("say set alarm for 5:30 am ")
|
||||
print("say set alarm for 5:30 am")
|
||||
tt = takeCommand()
|
||||
tt = tt.replace("set alarm to ", "")
|
||||
tt = tt.replace(".", "")
|
||||
tt = tt.upper()
|
||||
alarm(tt)
|
Loading…
Reference in New Issue
Block a user