Amazing-Python-Scripts

Форк
0
94 строки · 2.5 Кб
1
import os
2
import time
3
import speech_recognition as sr
4
import playsound
5
from gtts import gTTS
6
import random
7
import pyttsx3
8
import datetime
9
import time
10
import webbrowser
11
from ecapture import ecapture as ec
12

13

14
def speak(text):
15
    r1 = random.randint(1, 10000000)
16
    r2 = random.randint(1, 10000000)
17
    randfile = str(r2) + "randomtext" + str(r1) + ".mp3"
18
    tts = gTTS(text=text, lang='en', slow=False)
19
    tts.save(randfile)
20

21
    playsound.playsound(randfile)
22
    print(randfile)
23
    os.remove(randfile)
24

25

26
def get_audio():
27
    r = sr.Recognizer()
28
    with sr.Microphone() as source:
29
        r.adjust_for_ambient_noise(source, duration=1)
30
        # r.energy_threshold()
31
        print("say anything : ")
32
        audio = r.listen(source)
33
        try:
34
            said = r.recognize_google(audio)
35
            print(said)
36
        except:
37
            print("sorry, could not recognise")
38
    return said
39

40

41
engine = pyttsx3.init()
42
engine.say(
43
    "hello sir!, This is, Robot, Created by ,Sai Harsha , How can help you?")
44
# engine.setProperty('rate', 120)
45
engine.runAndWait()
46
text = get_audio()
47
if "PPT" or "ppt" or "intro" or "INTRO" in text:
48
    engine = pyttsx3.init()
49
    engine.say("Yes sir y not,")
50
    engine.setProperty('rate', 125)
51
    engine.runAndWait()
52
    os.system(r"d:\image.png")
53

54
elif "Google" or "google" or "GOOGLE" in text:
55
    engine = pyttsx3.init()
56
    engine.say("Yes sir y not,")
57
    engine.setProperty('rate', 125)
58
    engine.runAndWait()
59
    os.system("start \"\" https://www.google.com")
60

61
elif 'news' in text:
62
    engine = pyttsx3.init()
63
    news = webbrowser.open_new_tab(
64
        "https://timesofindia.indiatimes.com/home/headlines")
65
    engine.say('Here are some headlines from the Times of India,Happy reading')
66
    time.sleep(6)
67

68
elif 'search' in text:
69
    engine = pyttsx3.init()
70
    text = text.replace("search", "")
71
    webbrowser.open_new_tab(text)
72
    time.sleep(5)
73

74
elif 'time' in text:
75
    strTime = datetime.datetime.now().strftime("%H:%M:%S")
76
    engine = pyttsx3.init()
77
    engine.say(f"the time is {strTime}")
78

79
elif 'open gmail' in text:
80
    webbrowser.open_new_tab("gmail.com")
81
    engine = pyttsx3.init()
82
    engine.say("Google Mail open now")
83
    time.sleep(5)
84

85
elif 'open youtube' in text:
86
    webbrowser.open_new_tab("https://www.youtube.com")
87
    engine = pyttsx3.init()
88
    engine.say("youtube is open now")
89
    time.sleep(5)
90

91
elif "camera" in text or "take a photo" in text:
92
    ec.capture(0, "robo camera", "img.jpg")
93
    engine = pyttsx3.init()
94
    engine.say("ok")
95

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.