-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
65 lines (51 loc) · 2.41 KB
/
main.py
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
import os
import subprocess
import speech_recognition as sr
from app.utility import generate_audio, play_audio
from app.sos import help_sms
from app.multimodel import describe_surrounding, read_image
r = sr.Recognizer()
def start():
subprocess.run(["python", "model_data/main.py"])
def main():
global number
number = 0
while True:
number += 1
try:
with sr.Microphone() as mic:
print("Say something!...")
audio = r.listen(source=mic, phrase_time_limit=2 )
result = r.recognize_azure(audio_data=audio, key=os.getenv("AZURE_API_KEY"), language='en-US', location="centralus", profanity="masked")
print(result)
text = result[0]
if "start" in text.lower():
start()
if "stop" in text.lower():
print("Stop keyword detected. App is Closing ....")
break
if "describe" in text.lower():
print("describe keyword detected. Stop Audio streaming...")
#! code written by saniya
result = describe_surrounding()
generate_audio(result, str(number)+".mp3")
play_audio(str(number)+".mp3")
if "help" in text.lower():
print("help keyword detected. Stopping streaming...")
isreached = help_sms()
if isreached:
if(os.path.exists("audio/able_send_help.mp3") == False):
generate_audio("Help has been send to your location?", "able_send_help.mp3")
play_audio("able_send_help.mp3")
else:
if (os.path.exists("audio/unable_send_help.mp3") == False):
generate_audio("Failed to send help to your location. Please waiting help been sending.", "unable_send_help.mp3")
play_audio("unable_send_help.mp3")
if "read" in text.lower():
result = read_image()
generate_audio(result, "audio/"+str(number)+".mp3")
play_audio("audio/"+str(number)+".mp3")
except sr.UnknownValueError:
print("Could not understand audio")
if __name__ == "__main__":
main()