print colored("\nAdjusting for ambient noise!\n", 'yellow')
with sr.Microphone() as source:
    r.adjust_for_ambient_noise(source, duration=2)

# updates movies, music and photos is file system
ip.updateDirect(device)

# phrases often recognized when saying victoria
triggerList = [
    "victoria", "victorious", "pictorial", "victoriya", "call victoria",
    "pretoria", "vicktoria"
]

while (True):
    print colored("\nSay 'Victoria' to wake me up!\n", 'yellow')
    audio = ip.recordAudio(device)

    if (cr.isConnected()):
        if (device == 1): outText = cr.googleRecog(audio)
        else: outText = cr.bingRecog(audio)[0]
    else: outText = cr.sphinxRecog(audio)

    if (outText == -1):
        # if text is not recognized, continue listening
        continue
    elif (outText in ["exit", "Exit", "exact", "Exact"]):
        # exit the whole script
        print colored("\nEnding Session..\n", 'red')
        ip.play("Ending Session")
        break
    else:
Exemple #2
0
def mail(receiver_email, device):
    smtpObj = smtplib.SMTP('smtp.gmail.com', 587)

    # ping the smtp server
    smtpObj.ehlo()

    # start a ssl connection
    smtpObj.starttls()

    # sender email and password
    sender_email = ''
    account_password = ''

    # try to login, a frequent error occurs here
    try:
        smtpObj.login(sender_email, account_password)
    except:
        print colored("\nLogin Error!\n", 'red')
        ip.play("Login error!")
        return

    while (True):
        print colored("\nRecording subject of the mail..\n", 'yellow')
        ip.play("Recording subject of the mail..")

        audio = ip.recordAudio(device)
        if (cr.isConnected()): outText = cr.bingRecog(audio)[0]
        else: outText = cr.sphinxRecog(audio)

        if (outText == -1):
            # if text is not recognized, continue listening
            continue
        elif (outText in ["exit", "Exit", "exact", "Exact"]):
            # exit the whole script
            print colored("\nEnding Session..\n", 'red')
            ip.play("Ending Session")
            smtpObj.quit()
            return
        else:
            print colored("\nSubject is, " + outText + ". Is this correct?\n",
                          'green')
            ip.play("Subject is, " + outText + ". Is this correct?")

            audio = ip.recordAudio(device)
            if (cr.isConnected()): consent = cr.bingRecog(audio)[0]
            else: consent = cr.sphinxRecog(audio)

            if (consent.lower() in ["yes", "yah", "ya", "yup", "yes please"]):
                SUBJECT = outText
                break
            else:
                continue

    while (True):
        print colored("\nRecording body of the mail..\n", 'yellow')
        ip.play("Recording body of the mail..")

        audio = ip.recordAudio(device)
        if (cr.isConnected()): outText = cr.bingRecog(audio)[0]
        else: outText = cr.sphinxRecog(audio)

        if (outText == -1):
            # if text is not recognized, continue listening
            continue
        elif (outText in ["exit", "Exit", "exact", "Exact"]):
            # exit the whole script
            print colored("\nEnding Session..\n", 'red')
            ip.play("Ending Session")
            smtpObj.quit()
            return
        else:
            print colored("\nBody is, " + outText + ". Is this correct?\n",
                          'green')
            ip.play("Body is, " + outText + ". Is this correct?")

            audio = ip.recordAudio(device)
            if (cr.isConnected()): consent = cr.bingRecog(audio)[0]
            else: consent = cr.sphinxRecog(audio)

            if (consent.lower() in ["yes", "yah", "ya", "yup", "yes please"]):
                TEXT = outText
                break
            else:
                continue

    # create message object
    message = 'Subject: {}\n\n{}'.format(SUBJECT, TEXT)

    try:
        # send mail
        smtpObj.sendmail(sender_email, receiver_email, message)
        print colored("\nSuccessfully sent email\n", 'green')
    except:
        print colored("\nEmail not sent\n", 'red')

    # object needs to be closed
    smtpObj.quit()
    return
def youtube(textToSearch,flag,device):
	# flag=0 if link is available, flag=1 if text is to be searched
	if(flag==0):
		play(textToSearch,device)
	elif(flag==1):
		playLink(textToSearch,device)

	# videoPlaying is a flag to keep track if the video is playing
	videoPlaying = True
	
	# countyt keeps track of browser PIDs running in background
	# countyt=1 when the browser is not running
	countyt = 0
	
	while(countyt!=1):
		
		if(countyt==0): # <- runs only first time
			# wait for 5 seconds, so that video starts playing
			time.sleep(15)
			# then press F to enter full-screen mode
			ip.keypress(fullScreen_sequence)
		
		countyt = 0
		# read how many lines are there with "browser" in background running
		# around 7-8 when browser is running
		if(device==1):	p = os.popen("ps ux | grep chrome","r")
		else:	p = os.popen("ps ux | grep chromium","r")
		while(True):
			line = (p.readline()).strip()
			if not line: break
			countyt+=1

		# at this point, video is playing in browser in fullscreen mode
		# program is listening in background

		print colored("\nSay 'Victoria' access video controls!\n",'green')
		audio = ip.recordAudio(device);
		
		if(cr.isConnected()):
			if(device==1):	outText = cr.googleRecog(audio)
			else:	outText = cr.bingRecog(audio)[0]
		else: outText = cr.sphinxRecog(audio)

		# if text is not understood, continue listening
		if(outText==-1):
			continue

		# if text is understood
		else:
			# check if victoria is said
			if((outText.lower() in triggerList)or("victoria" in outText.lower())):
				# enters if text was victoria
				if(videoPlaying==True):
				# pause the video	
					ip.keypress(pause_sequence)
					videoPlaying = False
				ip.play("Which control sequence?")
				while(1):
					print colored("\nOptions available :",'yellow')
					print colored(videoControls,'yellow')
					print("\n")

					# record which video control has to be accessed
					audio = ip.recordAudio(device)
					if(cr.isConnected()): outText = cr.bingRecog(audio)[0]
					else: outText = cr.sphinxRecog(audio)

					# if above text is not recognized, ask again
					if(outText==-1):
						print colored("\nNot a control, try again!\n",'red')
						ip.play("Not a control, try again!")

					elif(outText.lower() in videoControls):
						# enter if text is a videoControl
						# convert text to lower for easier comparison
						text = outText.lower()
						if(text=="pause"):
							break

						# close the browser window as stop sequence
						elif(text=="stop"):
							ip.keypress(stop_sequence)
							time.sleep(1)
							return True
						
						elif(text=="play"):
							if(videoPlaying!=True):
								ip.keypress(pause_sequence)
								videoPlaying = True
								break
							else:
								print colored("\nVideo is already playing!\n",'red')
								break
						
						# for volume controls, press the concerned key 3 times
						# each with 1 second pause
						elif(text=="volume up"):
							for i in range(3):
								ip.keypress(volume_up_sequence)
								time.sleep(1)
							ip.keypress(pause_sequence)
							videoPlaying = True
							break
						
						elif(text=="volume down"):
							for i in range(3):
								ip.keypress(volume_down_sequence)
								time.sleep(1)
							ip.keypress(pause_sequence)
							videoPlaying = True
							break

					# if text is "exit", play video and stop listening
					elif(outText in ["exit","Exit","exact","Exact"]):
						print colored("\nExiting..\n",'red')
						ip.play("Exiting")
						ip.keypress(pause_sequence)
						videoPlaying = True
						break

			# if text is recognized but it is not victoria, continue listening
			else:
				continue

	return
Exemple #4
0
def mailDriver(device):
    while (True):
        print colored("\nTell me receiver's name..\n", 'yellow')
        ip.play("Tell me receiver's name..")

        audio = ip.recordAudio(device)
        if (cr.isConnected()): outText = cr.bingRecog(audio)[0]
        else: outText = cr.sphinxRecog(audio)

        if (outText == -1):
            # if text is not recognized, continue listening
            continue
        elif (outText in ["exit", "Exit", "exact", "Exact"]):
            # exit the whole script
            print colored("\nEnding Session..\n", 'red')
            ip.play("Ending Session")
            return
        else:
            print colored("\nShould I serch for " + outText + ". Yes or No?\n",
                          'green')
            ip.play("Should I search for " + outText + ". Yes or No?")

        consent = -1
        while (consent == -1):
            audio = ip.recordAudio(device)
            if (cr.isConnected()): consent = cr.bingRecog(audio)[0]
            else: consent = cr.sphinxRecog(audio)

            if (consent == -1):
                print colored("Didn't get it, recording again!", 'red')
                ip.play("Didn't get it, recording again!")

            if (consent.lower() in ["yes", "yah", "ya", "yup", "yes please"]):
                name = outText.lower()
                if (device == 1): os.chdir('/home/piyush/final')
                else: os.chdir('/home/pi/final')

                # open contacts list
                f = open("contacts.txt", "r")
                nameFound = False
                while (True):
                    line = (f.readline()).strip()
                    if not line: break
                    # match every name with recorded name
                    if (line.startswith(name)):
                        # contacts is a txt file with csvs : name,email
                        contactList = line.split(",")
                        print colored(
                            "\nShould I send it to " + contactList[0] + "?\n",
                            'yellow')
                        ip.play("Should I send it to " + contactList[0] + "?")

                        # record consent for name
                        consent = -1
                        while (consent == -1):
                            audio = ip.recordAudio(device)
                            if (cr.isConnected()):
                                consent = cr.bingRecog(audio)[0]
                            else:
                                consent = cr.sphinxRecog(audio)

                            if (consent == -1):
                                print colored(
                                    "Didn't get it, recording again!", 'red')
                                ip.play("Didn't get it, recording again!")

# if name is matched
                        if (consent.lower()
                                in ["yes", "yah", "ya", "yup", "yes please"]):
                            nameFound = True
                            # extract email
                            email = line.split(",")[1]
                            break

                        else:
                            continue

                if (nameFound == True):
                    mail(email, device)
                    return
                else:
                    print colored("\nNo one with such name found!\n", 'red')
                    ip.play("No one with such name found!")
                    continue
            else:
                continue
Exemple #5
0
def phraseRecog(device):
    print colored("\nTell me the phrase word!\n", 'green')
    ip.play("Tell me the phrase word!")

    while (True):
        print colored("\nPhraseList : ", 'yellow')
        print colored(phrases, 'yellow')
        print("\n")

        sleep(2)

        # listen to the phrase word
        audio = ip.recordAudio(device)
        if (cr.isConnected()):
            if (device == 1): outText = cr.googleRecog(audio)
            else: outText = cr.bingRecog(audio)[0]
        else: outText = cr.sphinxRecog(audio)

        # if voice not recognized
        if (outText == -1):
            print colored("\nDidn't get it, please try again\n", 'red')
            ip.play("Didn't get it, please try again")

        # if user says exit, return from the main function
        elif (outText in ["exit", "Exit"]):
            print colored("\nEnding Session..\n", 'red')
            ip.play("Ending Session")
            return

        # if voice is recognized and it is not "exit"
        else:
            # convert to lower letters for easier comparison
            outText = outText.lower()

            # if word is a phrase word
            if (outText in phraseList):
                # if movie is said
                if (outText in ["movie", "movies"]):
                    print colored("\nWhich movie to play?\n", 'green')
                    ip.play("Which movie to play?")
                    while (True):
                        # print all movie names by printing out.txt
                        print colored("Possible Options :", 'green')
                        if (device == 1): os.chdir('/home/piyush/ied/movies')
                        else: os.chdir('/home/pi/ied/movies')
                        os.system('cat out.txt')
                        print("\n")

                        # record movie name
                        audio = ip.recordAudio(device)
                        if (cr.isConnected()):
                            movieName = cr.bingRecog(audio)[0]
                        else:
                            movieName = cr.sphinxRecog(audio)

                        # if user says exit, exit main function
                        if (movieName in ["exit", "Exit", "exact", "Exact"]):
                            print colored("\nEnding Session..\n", 'red')
                            ip.play("Ending Session")
                            return

                        # po.playMovie(movieName) returns false if movie doesn't exist
                        # plays the movie and returns true if movie exists
                        if (po.playMovie(movieName, device)): return

                        else:
                            # if po.playMovie(movieName) returns false, give error message
                            print colored(
                                "\nNo movie with such name exists! Try again.\n",
                                'red')
                            ip.play(
                                "No movie with such name exists! Try again.")

                # if music is said
                elif (outText in ["music"]):
                    # ask if user wants to play specific track or shuffle all the avail. tracks
                    print colored("\nTrack or shuffle\n", 'green')
                    ip.play("Track or shuffle")

                    while (True):
                        # record tracks or shuffle
                        audio = ip.recordAudio(device)
                        if (cr.isConnected()):
                            musicOption = cr.bingRecog(audio)[0]
                        else:
                            musicOption = cr.sphinxRecog(audio)

                        # if user says exit, return the main function
                        if (musicOption in ["exit", "Exit", "exact", "Exact"]):
                            print colored("\nEnding Session..\n", 'red')
                            ip.play("Ending Session")
                            return

                        # if track is said
                        if (musicOption in ["track", "Track"]):
                            print colored("Which track to play?", 'green')
                            ip.play("Which track to play?")

                            while (True):
                                # print all the possible options by printing out.txt
                                print colored("\nPossible Options :\n",
                                              'green')
                                if (device == 1):
                                    os.chdir('/home/piyush/ied/music')
                                else:
                                    os.chdir('/home/pi/ied/music')
                                os.system('cat out.txt')
                                print("\n")

                                # record track name
                                audio = ip.recordAudio(device)
                                if (cr.isConnected()):
                                    musicName = cr.bingRecog(audio)[0]
                                else:
                                    musicName = cr.sphinxRecog(audio)

                                # if exit is said, exit the main function
                                if (musicName
                                        in ["exit", "Exit", "exact", "Exact"]):
                                    print colored("\nEnding Session..\n",
                                                  'red')
                                    ip.play("Ending Session")
                                    return

                                # po.playTrack(musicName) returns false if track doesn't exist
                                # plays the track and returns true if track exists
                                if (po.playTrack(musicName, device)): return

                                else:
                                    # if po.playMovie(movieName) returns false, give error message
                                    print colored(
                                        "\nNo track with such name exists! Try again.\n",
                                        'red')
                                    ip.play(
                                        "No track with such name exists! Try again."
                                    )

                        # if user wants to shuffle tracks
                        elif (musicOption in ["shuffle", "Shuffle"]):
                            po.shuffle(device)
                            return

                        # if user says something instead of track or shuffle
                        else:
                            print colored("\nWrong Option! Try again.\n",
                                          'red')
                            ip.play("Wrong Option! Try again.")

                # if photos is said
                # works only for albums stored as folders
                elif (outText in ["photos", "photo"]):
                    print colored("Which album to play?", 'green')
                    ip.play("Which album to play?")

                    while (True):
                        # show all albums stored
                        print colored("\nPossible Options :", 'green')
                        if (device == 1): os.chdir('/home/piyush/ied/photos')
                        else: os.chdir('/home/pi/ied/photos')
                        os.system('cat out.txt')

                        # recored the album name
                        audio = ip.recordAudio(device)
                        if (cr.isConnected()):
                            albumName = cr.bingRecog(audio)[0]
                        else:
                            albumName = cr.sphinxRecog(audio)

                        # if user says exit, exit the main function
                        if (albumName in ["exit", "Exit", "exact", "Exact"]):
                            ip.play("Ending Session")
                            print colored("\nEnding Session..\n", 'red')
                            return

                        # po.playPhotos(albumName) returns false if album doesn't exist
                        # plays the album and returns true if album exists
                        if (po.playPhotos(albumName, device)): return

                        else:
                            # if po.playPhotos(albumName) returns false, give error message
                            print colored(
                                "\nNo album with such name exists! Try again.\n",
                                'red')
                            ip.play(
                                "No album with such name exists! Try again.")

                # to access calender
                # currently programmed to only show upcoming 5 events
                # creating a new event functionality is implemented
                # but not used due to the recognition constraints
                # future scope : add insertion and deletion of events
                elif (outText == "schedule"):
                    print colored("\nUpcoming events are..\n", 'green')
                    ip.play("Upcoming events are")
                    calender.main()
                    return

                # if alarm is said
                # sets an alarm for the first occurrence of the recorded time
                # this won't work offline
                # future scope : tell the date and set an alarm for a particular day
                elif (outText == "alarm"):
                    print colored("\nTell me the time?\n", 'green')
                    ip.play("Tell me the time?")
                    while (True):
                        # record alarm time
                        audio = ip.recordAudio(device)
                        if (cr.isConnected()):
                            (query, time) = cr.bingRecog(audio)
                        else:
                            print colored("\nNot connected to the internet.\n",
                                          'red')
                            return

                        # if user says exit, exit the main function
                        if (query in ["exit", "Exit", "exact", "Exact"]):
                            print colored("\nEnding Session..\n", 'red')
                            ip.play("Ending Session")
                            return

                        # if text is not understood, record again
                        elif (query == -1):
                            print("\nWhat did you say?\n", 'red')
                            ip.play("What did you say?")
                            continue

                        # if something else is recognized
                        else:
                            # time -> 8 21 PM
                            # query -> eight twenty one PM

                            # extract last two words
                            ampm = query[len(query) - 2:]

                            # check if they are am or pm
                            # if not record again
                            if (ampm.lower() not in ["am", "pm"]):
                                print colored(
                                    "\nWrong format! Recording again..\n",
                                    'red')
                                ip.play("Wrong format! Recording again..")
                                continue

                            # remove last two letters from time and query
                            time = time[:len(time) - 2]
                            query = query[:len(query) - 2]
                            splitQuery = query.split(" ")

                            # case because 1 is often recognised as vine
                            if (splitQuery[0] == "vine"):
                                hour = "1"
                                time = time[4:]
                            # case because 2 is often recognised as do
                            elif (splitQuery[0] == "do"):
                                hour = "2"
                                time = time[2:]
                            elif (splitQuery[0] in ["ten", "eleven",
                                                    "twelve"]):
                                hour = time[:2]
                                time = time[2:]
                            else:
                                hour = time[:1]
                                time = time[1:]
                            if (time.startswith(":")):
                                time = time[1:]

                            minutes = time.strip(" ")

                            # if minutes is empty
                            if (minutes in [None, " ", ""]):
                                minutes = "0"

                            try:
                                # check if "hour" and "minutes" contains numbers or not
                                int(hour)
                                int(minutes)
                            except:
                                print colored(
                                    "\nWrong format! Recording again..\n",
                                    'red')
                                ip.play("Wrong format! Recording again..")
                                continue

                            # confirm the alarm details
                            print colored(
                                "\nShould I set an alarm for " + hour + " " +
                                minutes + " " + ampm + "? Yes or No?\n",
                                'green')
                            ip.play("Should I set an alarm for " + hour + " " +
                                    minutes + " " + ampm + "? Yes or No?")

                            while (True):
                                # record consent
                                audio = ip.recordAudio(device)
                                if (cr.isConnected()):
                                    consent = cr.bingRecog(audio)[0]
                                else:
                                    consent = cr.sphinxRecog(audio)

                                consent = str(consent).lower()
                                if (consent in [
                                        "yes", "yah", "ya", "yup", "yes please"
                                ]):
                                    # on confirming set alarm and exit the main function
                                    alarm.set(hour, minutes, ampm, device)
                                    return

                                else:
                                    # record time again if user says no
                                    print colored("\nRecording time again..\n",
                                                  'green')
                                    ip.play("Recording time again")
                                    break

                # if user wants to perform a google search
                elif (outText == "search"):
                    print colored("\nWhat should I search for?\n", 'green')
                    ip.play("What should I search for?")
                    while (True):
                        # record search query
                        audio = ip.recordAudio(device)
                        if (cr.isConnected()): query = cr.bingRecog(audio)[0]
                        else: query = cr.sphinxRecog(audio)

                        # exit the main function
                        if (query in ["exit", "Exit", "exact", "Exact"]):
                            print colored("\nEnding Session..\n", 'red')
                            ip.play("Ending Session")
                            return

                        # if voice is not understood
                        elif (query == -1):
                            print colored("\nWhat did you say?\n", 'red')
                            ip.play("What did you say?")
                            continue

                        # if voice is recognized
                        else:
                            # confirm the search query
                            print colored(
                                "\nShould I search for " + query +
                                "? Yes or No?\n", 'green')
                            ip.play("Should I search for " + query +
                                    "? Yes or No?")

                            while (True):
                                # record consent
                                audio = ip.recordAudio(device)
                                if (cr.isConnected()):
                                    consent = cr.bingRecog(audio)[0]
                                else:
                                    consent = cr.sphinxRecog(audio)

                                try:
                                    consent = consent.lower()
                                except:
                                    print colored("\nPardon?\n", 'red')
                                    ip.play("Pardon?")
                                    continue

                                if (consent in [
                                        "yes", "yah", "ya", "yup", "yes please"
                                ]):
                                    # perform the google search and exit the main fucntion
                                    google.search(query, device)
                                    return

                                else:
                                    # if the user says no to the recognized text
                                    print colored(
                                        "\nRecording search query again..\n",
                                        'green')
                                    ip.play("Recording search query again")
                                    break

                # if user wants news
                elif (outText == "news"):
                    google.searchNews()
                    return

                elif (outText in ["mail", "male", "man", "men"]):
                    mail.mailDriver(device)
                    return

                # if user wants to watch a youtube video
                elif (outText == "youtube"):
                    print colored("\nWhich video should I search for?\n",
                                  'green')
                    ip.play("Which video should I search for?")
                    while (True):
                        # record video name
                        audio = ip.recordAudio(device)
                        if (cr.isConnected()):
                            videoName = cr.bingRecog(audio)[0]
                        else:
                            videoName = cr.sphinxRecog(audio)

                        # exit the main function
                        if (videoName in ["exit", "Exit", "exact", "Exact"]):
                            print colored("\nEnding Session..\n", 'red')
                            ip.play("Ending Session")
                            return

                        # if text is not understood
                        elif (videoName == -1):
                            print colored("\nWhat did you say?\n", 'red')
                            ip.play("What did you say?")
                            continue

                        # if text is understood
                        else:
                            # confirm the video name
                            print colored(
                                "\nShould I search for " + videoName +
                                "? Yes or No?\n", 'green')
                            ip.play("Should I search for " + videoName +
                                    "? Yes or No?")

                            while (True):
                                # record confirmation
                                audio = ip.recordAudio(device)
                                if (cr.isConnected()):
                                    consent = cr.bingRecog(audio)[0]
                                else:
                                    consent = cr.sphinxRecog(audio)

                                consent = consent.lower()
                                if (consent in [
                                        "yes", "yah", "ya", "yup", "yes please"
                                ]):
                                    # play the youtube video and exit main function
                                    you.youtube(videoName, 0, device)
                                    return

                                else:
                                    # if user says no to recognized text, record again
                                    print colored(
                                        "\nRecording the video name again..\n",
                                        'green')
                                    ip.play("Recording the video name again")
                                    break

            # if the word recognied is not a phrase word
            else:
                print colored(
                    "\n" + outText + " is not a phrase, try again.\n", 'red')
                ip.play(outText + " is not a phrase, try again.")
def playMovie(name,device):
	if(device==1):	os.chdir('/home/piyush/ied/movies')
	else:	os.chdir('/home/pi/ied/movies')
	
	# store file names in a python list
	with open("out.txt") as f:
		content = f.readlines()
	content = [x.strip() for x in content]

	name = str(name)

	# concatenate the extension for matching
	nameList = [name+".mkv",name+".avi",name+".mp4"]
	flag = False

	# check if movie exists
	for i in nameList:
		for j in content:
			if(i==j):
				play = i
				flag = True
				break

	# return false and exit if movie name not found
	if(flag==False):
		return False
	else:
		# play the movie using mplayer if movie is found
		mCommand = "'"+"mplayer -fs "+play+"'"
		if(device==1):	command = "gnome-terminal --command "+mCommand
		else:	command = "lxterminal --command "+mCommand
		os.system(command)

		moviePlaying = True
		count = 0
		time.sleep(10)

		while(count!=2):
			p = os.popen("ps ux | grep mplayer","r")
			count = 0
			while(True):
				line = (p.readline()).strip()
				if not line: break
				count+=1

			print colored("\nSay 'Victoria' access movie controls!\n",'green')
			audio = ip.recordAudio(device);
			
			if(cr.isConnected()): 
				if(device==1):	outText = cr.googleRecog(audio)
				else:	outText = cr.bingRecog(audio)[0]
			else: outText = cr.sphinxRecog(audio)

			if(outText==-1):
				continue
			else:
				if((outText.lower() in triggerList)or("victoria" in outText.lower())):
					if(moviePlaying==True):	ip.keypress(pause_sequence)
					moviePlaying = False
					ip.play("Which control sequence?")
					while(1):
						print colored("\nOptions available :\n",'yellow')
						print colored(movieControls,'yellow')
						print("\n")

						audio = ip.recordAudio(device)
						if(cr.isConnected()): outText = cr.bingRecog(audio)[0]
						else: outText = cr.sphinxRecog(audio)

						if(outText==-1):
							print colored("\nNot a control, try again!\n",'red')
							ip.play("Not a control, try again!")

						elif(outText.lower() in movieControls):
							text = outText.lower()
							if(text=="pause"):
								break
							elif(text=="stop"):
								ip.keypress(stop_sequence)
								time.sleep(1)
								return True
							elif(text=="play"):
								if(moviePlaying!=True):
									ip.keypress(pause_sequence)
									moviePlaying = True
									break
								else:
									print colored("\nMovie is already playing!\n",'red')
									break
							elif(text=="volume up"):
								for i in range(3):
									ip.keypress(volume_up_sequence)
									time.sleep(1)
								if(device!=1):  ip.keypress(pause_sequence)
								moviePlaying = True
								break
							elif(text=="volume down"):
								for i in range(3):
									ip.keypress(volume_down_sequence)
									time.sleep(1)
								if(device!=1):  ip.keypress(pause_sequence)
								moviePlaying = True
								break

						elif(outText in ["exit","Exit","exact","Exact"]):
							print colored("\nExiting..\n",'red')
							ip.play("Exiting")
							ip.keypress(pause_sequence)
							moviePlaying = True
							break

					
		return True
def playPhotos(name,device):
	if(device==1):	os.chdir('/home/piyush/ied/photos')
	else:	os.chdir('/home/pi/ied/photos')
	
	with open("out.txt") as f:
		content = f.readlines()
	content = [x.strip() for x in content]

	flag = False

	# search for album name
	for i in content:
		if(i == name):
			play = i
			flag = True
			break

	# return False and exit if album doesn't exist
	if(flag==False):
		return False
	else:
		# play using eog fullscreen/slideshow command
		command = "eog "+play+" -s"

		if(device==1):	command1 = "gnome-terminal --command='"+command+"'"
		else:	command1 = "lxterminal --command='"+command+"'"

		os.system(command1)

		photosPlaying = True
		count = 0

		# wait 5 seconds for the slideshow to startup
		time.sleep(5)

		# no. of processes with keyword 'eog' when eog not playing = 1
		while(count!=1):
			p = os.popen("ps ux | grep eog","r")
			count = 0
			while(True):
				line = (p.readline()).strip()
				if not line: break
				count+=1

			print colored("\nSay 'Victoria' access photo controls!\n",'green')
			audio = ip.recordAudio(device);
			
			if(cr.isConnected()): 
				if(device==1):	outText = cr.googleRecog(audio)
				else:	outText = cr.bingRecog(audio)[0]
			else: outText = cr.sphinxRecog(audio)

			if(outText==-1):
				continue
			else:
				if((outText.lower() in triggerList)or("victoria" in outText.lower())):
					if(photosPlaying==True):	ip.keypress(pause_sequence)
					photosPlaying = False
					ip.play("Which control sequence?")
					while(1):
						print colored("\nOptions available :\n",'yellow')
						print colored(photoControls,'yellow')
						print("\n")

						audio = ip.recordAudio(device)
						if(cr.isConnected()): outText = cr.bingRecog(audio)[0]
						else: outText = cr.sphinxRecog(audio)

						if(outText==-1):
							print colored("\nNot a control, try again!\n",'red')
							ip.play("Not a control, try again!")

						elif(outText.lower() in photoControls):
							text = outText.lower()
							if(text=="pause"):
								break
							elif(text=="stop"):
								# stop by killing using PID
								k = os.popen("ps ux | grep 'eog "+play+" -s'","r")
								k = (k.readline()).strip()
								
								# print colored("\n"+k+"\n",'yellow')
								
								pid = (k.split())[1]
								command2 = "kill -9 "+pid
								os.system(command2)

								time.sleep(2)
								return True
							elif(text=="play"):
								if(photosPlaying!=True):
									ip.keypress(pause_sequence)
									photosPlaying = True
									break
								else:
									print colored("\nAlbum is already playing!\n",'red')
									break

						elif(outText in ["exit","Exit","exact","Exact"]):
							print colored("\nExiting..\n",'red')
							ip.play("Exiting")
							ip.keypress(pause_sequence)
							photosPlaying = True
							break

		return True
def musicControlFunc(device):
	musicPlaying = True
	count = 0
	time.sleep(10)

	while(count!=2):
		p = os.popen("ps ux | grep mplayer","r")
		count = 0
		while(True):
			line = (p.readline()).strip()
			if not line: break
			count+=1

		print colored("\nSay 'Victoria' access music controls!\n",'green')
		audio = ip.recordAudio(device);
		
		if(cr.isConnected()): 
			if(device==1):	outText = cr.googleRecog(audio)
			else:	outText = cr.bingRecog(audio)[0]
		else: outText = cr.sphinxRecog(audio)

		if(outText==-1):
			continue
		else:
			if((outText.lower() in triggerList)or("victoria" in outText.lower())):
				if(musicPlaying==True):	ip.keypress(pause_sequence)
				musicPlaying = False
				
				while(1):
					print colored("\nOptions available :\n",'yellow')
					print colored(movieControls,'yellow')
					print("\n")

					ip.play("Which control sequence?")

					audio = ip.recordAudio(device)
					if(cr.isConnected()): outText = cr.bingRecog(audio)[0]
					else: outText = cr.sphinxRecog(audio)

					if(outText==-1):
						print colored("\nNot a control, try again!\n",'red')
						ip.play("Not a control, try again!")

					elif(outText.lower() in movieControls):
						text = outText.lower()
						if(text=="pause"):
							break
						elif(text=="stop"):
							ip.keypress(stop_sequence)
							time.sleep(1)
							return True
						elif(text=="play"):
							if(musicPlaying!=True):
								ip.keypress(pause_sequence)
								musicPlaying = True
								break
							else:
								print colored("\nMusic is already playing!\n",'red')
								break
						elif(text=="volume up"):
							for i in range(3):
								ip.keypress(volume_up_sequence)
								time.sleep(1)
							if(device!=1):  ip.keypress(pause_sequence)
							musicPlaying = True
							break
						elif(text=="volume down"):
							for i in range(3):
								ip.keypress(volume_down_sequence)
								time.sleep(1)
							if(device!=1):  ip.keypress(pause_sequence)
							musicPlaying = True
							break

					elif(outText in ["exit","Exit","exact","Exact"]):
						print colored("\nExiting..\n",'red')
						ip.play("Exiting")
						ip.keypress(pause_sequence)
						musicPlaying = True
						break
	return True