Amazing-Python-Scripts
94 строки · 2.5 Кб
1import os2import time3import speech_recognition as sr4import playsound5from gtts import gTTS6import random7import pyttsx38import datetime9import time10import webbrowser11from ecapture import ecapture as ec12
13
14def speak(text):15r1 = random.randint(1, 10000000)16r2 = random.randint(1, 10000000)17randfile = str(r2) + "randomtext" + str(r1) + ".mp3"18tts = gTTS(text=text, lang='en', slow=False)19tts.save(randfile)20
21playsound.playsound(randfile)22print(randfile)23os.remove(randfile)24
25
26def get_audio():27r = sr.Recognizer()28with sr.Microphone() as source:29r.adjust_for_ambient_noise(source, duration=1)30# r.energy_threshold()31print("say anything : ")32audio = r.listen(source)33try:34said = r.recognize_google(audio)35print(said)36except:37print("sorry, could not recognise")38return said39
40
41engine = pyttsx3.init()42engine.say(43"hello sir!, This is, Robot, Created by ,Sai Harsha , How can help you?")44# engine.setProperty('rate', 120)
45engine.runAndWait()46text = get_audio()47if "PPT" or "ppt" or "intro" or "INTRO" in text:48engine = pyttsx3.init()49engine.say("Yes sir y not,")50engine.setProperty('rate', 125)51engine.runAndWait()52os.system(r"d:\image.png")53
54elif "Google" or "google" or "GOOGLE" in text:55engine = pyttsx3.init()56engine.say("Yes sir y not,")57engine.setProperty('rate', 125)58engine.runAndWait()59os.system("start \"\" https://www.google.com")60
61elif 'news' in text:62engine = pyttsx3.init()63news = webbrowser.open_new_tab(64"https://timesofindia.indiatimes.com/home/headlines")65engine.say('Here are some headlines from the Times of India,Happy reading')66time.sleep(6)67
68elif 'search' in text:69engine = pyttsx3.init()70text = text.replace("search", "")71webbrowser.open_new_tab(text)72time.sleep(5)73
74elif 'time' in text:75strTime = datetime.datetime.now().strftime("%H:%M:%S")76engine = pyttsx3.init()77engine.say(f"the time is {strTime}")78
79elif 'open gmail' in text:80webbrowser.open_new_tab("gmail.com")81engine = pyttsx3.init()82engine.say("Google Mail open now")83time.sleep(5)84
85elif 'open youtube' in text:86webbrowser.open_new_tab("https://www.youtube.com")87engine = pyttsx3.init()88engine.say("youtube is open now")89time.sleep(5)90
91elif "camera" in text or "take a photo" in text:92ec.capture(0, "robo camera", "img.jpg")93engine = pyttsx3.init()94engine.say("ok")95