-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecordAudio.py
More file actions
90 lines (73 loc) · 3.21 KB
/
RecordAudio.py
File metadata and controls
90 lines (73 loc) · 3.21 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import speech_recognition as sr
import webbrowser
import pyttsx3
import time
t = time.localtime()
engine = pyttsx3.init() # object creation
##Rates
rate = engine.getProperty('rate') # getting details of current speaking rate
engine.setProperty('rate', 130) # setting up new voice rate
#Volume
volume = engine.getProperty('volume') #getting to know current volume level (min=0 and max=1)
engine.setProperty('volume',1.0) # setting up volume level between 0 and 1
#Voice
voices = engine.getProperty('voices') #getting details of current voice
#engine.setProperty('voice', voices[1].id) #changing index, changes voices. o for male
engine.setProperty('voice', voices[0].id) #changing index, changes voices. 1 for female
r = sr.Recognizer() # initialise a recogniser
# listen for audio and convert it to text:
def RecordAudio(ask=False):
with sr.Microphone() as source: # microphone as source
engine.say("command input")
engine.runAndWait()
audio = r.listen(source) # listen for the audio via source
print(">> " + r.recognize_google(audio))
voice_data = ''
try:
engine.runAndWait()
voice_data = r.recognize_google(audio) # convert audio to text
except sr.UnknownValueError: # error: recognizer does not understand
engine.say('I did not get that, try again')
engine.runAndWait()
except sr.RequestError:
engine.say('Sorry, the service is down') # error: recognizer is not connected
engine.runAndWait()
return voice_data.lower()
def respond(voice_data):
if 'what is your name' in voice_data or 'name' in voice_data:
engine.say('Intelligence AI Version 0.1 made by Ariel')
engine.runAndWait()
if 'commands' in voice_data or 'help' in voice_data or 'hope' in voice_data:
engine.say('For Check my name say, Name')
engine.say('For Search say, Search')
engine.say('For Music say, Music')
engine.say('For Time say, Time')
engine.say('For Search location say, location')
engine.say('For Youtube say, Youtube')
engine.runAndWait()
if 'search' in voice_data or 'google' in voice_data:
engine.say('What do you want to search for?')
engine.runAndWait()
search = RecordAudio()
url = 'https://google.com/search?q=' + search
webbrowser.get().open(url)
engine.say('Here is what i found for ' + search)
engine.runAndWait()
if 'location' in voice_data:
engine.say('What location you want to search?')
engine.runAndWait()
location = RecordAudio()
url ='https://google.com/maps/place/' + location
webbrowser.get().open(url)
engine.say('Here is the location of ' + location)
if 'youtube' in voice_data or 'music' in voice_data or 'YouTube' in voice_data:
engine.say('what do you want to search for?')
engine.runAndWait()
youtube = RecordAudio()
url = 'https://www.youtube.com/results?search_query=' + youtube
webbrowser.get().open(url)
if 'time' in voice_data:
engine.say(time.asctime(t))
engine.runAndWait()
if 'exit' in voice_data:
exit()