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