def test(self, string, w): ''' Function to take the recording and check if it matches with the letters. :param string: The string to be formed as the result. :param w: The specific letter to be checked. :return: Returns string, improvised by the function itself. ''' self.counter += 1 with self.lock: record = recorder.Recorder("../../../Language_Models/", "../../../Acoustic_Models/", SILENCE=1, TRIALS=1, DECODE=True, L_LIB="characters", A_LIB="en-us", OUTPUT_SHELL="./decoder.sh") record.start() f = open("./file.txt", "r") letter = f.read().strip() if letter.lower() == w: string = string + w return string else: return "-"
def formation(w, q): print("Meaning of the word is: ") for meaning in mean[q]: print(meaning) k = 0 str1 = "" global string string = "" if "-" not in w[:]: for i in range(0, len(w)): string = string + "-" for i in range(0, len(string)): str1 = str1 + string[i] + " " else: string = w str1 = w print(str1) str1 = "" while k < 15: k = k + 1 str1 = "" letter = "" print("Enter letter: ") with lock: record = recorder.Recorder("../../../Language_Models/", "../../../Acoustic_Models/", L_LIB="characters", A_LIB="en-us", DECODE=True, TRIALS=1, SILENCE=1) record.start() r = open('./test.hyp', 'r') arr = r.read().split(" ") letter = arr[0] print(letter) lt = letter.lower() r.close() try: string = str(check(str1, lt, w)) except Exception as e: print(e) str1 = "" for j in range(0, len(string)): str1 = str1 + string[j] + " " print(str1) if string == q or k == 15: return string elif int(round(time.time()) - start) >= 180: subprocess.call(["espeak", "You lose"]) break return "End"
def terminal(self, word): ''' Calls the other functions to run the entire terminal version of the game. :param word: The word which is generated randomly using function rand() ''' self.str1 = self.initialize(word) print(self.str1) self.str1 = "" while self.counter < 20: self.counter = self.counter + 1 self.str1 = "" letter = "" print("Enter letter: ") with self.lock: record = recorder.Recorder("../../../Language_Models/", "../../../Acoustic_Models/", L_LIB="characters", A_LIB="en-us", SILENCE=1, TRIALS=1, DECODE=True) record.start() r = open('./test.hyp', 'r') arr = r.read().split(" ") letter = arr[0] print(letter) lt = letter.lower() r.close() try: self.string = str(self.check(self.str1, lt, word)) except Exception as e: print(e) self.str1 = "" for j in range(0, len(self.string)): self.str1 = self.str1 + self.string[j] + " " print(self.str1) if self.string == word: subprocess.call(["espeak", "You win"]) break elif self.counter == 20: subprocess.call(["espeak", "You lose"]) with self.lock: subprocess.call(["espeak", "The answer is " + word]) print(" Answer is: " + word)
def choose(self): ''' Module to help take the user input for the chosen option. The valid inputs are 1, 2 and 3. ''' subprocess.call( ["espeak", " Choose your option 1 Encode 2 Decode 3 Guess "]) with self.lock: record = recorder.Recorder("../../../Language_Models/", LIB_FILE="num", TRIALS=1, DECODE=True, SILENCE=1) record.start() r = open('./test.hyp', 'r') arr = r.read().split(" ") letter = arr[0] r.close() return letter
def formation(self, w, q): ''' Main function, which just like in hangman, forms the string taking the user-input at every time. Here the q argument is mainly aimed at specifying the word number such that the meaning of it can be displayed as a hint. The main task of this function is to run a sequence like the Hangman game to complete each of the four words. If the number of trials exceed 15 for each word...it shifts to the next word...and again back to it if time permits...in order to strive towards the solution. However, if the time of game-running exceeds 3 minutes...the game stops. :param w: The qth word generated from Crossword script. :param q: The index of the word. :return: The updated string if within game-running time, or else returns "END". ''' string1 = "" mean_string = "Meaning of the word is :" f = pygame.font.SysFont(None, 25) word_surf = f.render(mean_string, True, self.green) word_wid, word_hei = word_surf.get_size() self.multi_line_text(self.gameDisplay, mean_string, (0, self.display_height / 10), 25, self.green, self.black) pygame.display.update() self.multi_line_text(self.gameDisplay, self.n, (word_wid, self.display_height / 8), 25, self.black, self.black) pygame.display.update() for meaning in self.mean[q]: print(meaning) string1 = string1 + meaning + "\n" self.multi_line_text(self.gameDisplay, string1, (word_wid, self.display_height / 8), 25, self.white) pygame.display.update() self.n = string1 k = 0 str1 = "" global string string = "" if "-" not in w[:]: for i in range(0, len(w)): string = string + "-" for i in range(0, len(string)): str1 = str1 + string[i] + " " else: string = w str1 = w self.message(self.m, self.black, self.display_width / 2, self.display_height / 3, 30, True, self.black) pygame.display.update() self.message("Output: " + str1, self.white, self.display_width / 2, self.display_height / 3, 30, True) pygame.display.update() self.m = "Output: " + str1 str1 = "" subprocess.call(["espeak", "Guess the word"]) while k < 15: k = k + 1 str1 = "" letter = "" print("Enter letter: ") subprocess.call(["espeak", "Trials left " + str(16 - k)]) with self.lock: record = recorder.Recorder("../../../Language_Models/", LIB_FILE="characters", DECODE=True, TRIALS=1, SILENCE=1) record.start() r = open('./test.hyp', 'r') arr = r.read().split(" ") letter = arr[0] print(letter) lt = letter.lower() r.close() try: string = str(self.check(str1, lt, w)) except Exception as e: print(e) str1 = "" for j in range(0, len(string)): str1 = str1 + string[j] + " " self.message(self.m, self.black, self.display_width / 2, self.display_height / 3, 30, True, self.black) pygame.display.update() self.message("Output: " + str1, self.white, self.display_width / 2, self.display_height / 3, 30, True) pygame.display.update() self.m = "Output: " + str1 if string == q or k == 15: return string elif int(round(time.time()) - self.start) >= 180: subprocess.call(["espeak", "Time is up You lose"]) break return "End"
def terminal(self, choice, random_word): ''' Main module to run the entire game in terminal :param choice: Choice 1, 2 or 3 as user input. :param random_word: Random word generated using rand_word() ''' if choice == "1": s = self.rand_int() hint = self.shift("anirban", s) with self.lock: subprocess.call( ["espeak", " If anirban is encoded as " + str(hint)]) hint_str = "" for h in hint: hint_str = hint_str + h print("anirban -> " + hint_str) encode = self.shift(random_word, s) with self.lock: subprocess.call(["espeak", " Then encode " + random_word]) print(random_word + " ->" + " ?") self.check(encode) elif choice == "2": s = self.rand_int() hint = self.shift("anirban", s) hint_str = "" for h in hint: hint_str = hint_str + h with self.lock: subprocess.call( ["espeak", " If " + str(hint) + "is decoded as anirban"]) print(hint_str + " -> anirban") encode = self.shift(random_word, s) with self.lock: subprocess.call(["espeak", " Then decode " + str(encode)]) encode_str = "" for h in encode: encode_str = encode_str + h print(encode_str + " ->" + " ?") self.check(random_word) elif choice == "3": s = self.rand_int() e = "" encode = self.shift(random_word, s) encode_str = "" for p in encode: encode_str = encode_str + p print(random_word + "-> " + encode_str) for k in range(10): subprocess.call(["espeak", " Enter shifting key"]) with self.lock: rec = recorder.Recorder("../../../Language_Models/", "../../../Acoustic_Models/", L_LIB="num", A_LIB="en-us", TRIALS=1, DECODE=True, SILENCE=1) rec.start() r = open('./test.hyp', 'r') arr = r.read().split(" ") num = arr[0] r.close() try: e = encrypter.shift(random_word, int(num)) except Exception as z: print(z) e_str = "" for p in e: e_str = e_str + p print(e_str) if e_str == encode_str: subprocess.call(["espeak", "-s", "120", " Good!"]) elif k == 9: subprocess.call([ "espeak", "-s", "120", " No you are wrong...the answer will be " ]) for j in random_word: subprocess.call(["espeak", "-s", "100", j]) else: subprocess.call(["espeak", " Wrong choice"])
import sys sys.path.insert(0, "../../") from API import recorder, edit record = recorder.Recorder("../../Language_Models/", "../../Acoustic_Models/", L_LIB="commands", A_LIB="en-us", DECODE=True, OUTPUT_SHELL="./launch.sh") record.start()
def main(): ''' The main block of the program which runs the entire display. ''' pygame.init() # Initialize pygame global encrypter encrypter = Encrypter.Encrypter() global m, black, white, green, blue, red, display_width, display_height choice = "" m = "" while True: try: random_word = encrypter.rand_word() break except Exception as e: print(e) white = (255, 255, 255) red = (255, 0, 0) black = (0, 0, 0) blue = (0, 0, 255) green = (0, 255, 0) global gameDisplay gameDisplay = pygame.display.set_mode( (800, 600)) # Pass a tuple as a parameter display_width = 800 display_height = 600 pygame.display.set_caption("Encrypter") pygame.display.update() # Update the specific modification clock = pygame.time.Clock() gameExit = False while not gameExit: message("Encrypter", blue, display_width / 7, display_height / 7, 50) pygame.display.update() while True: choice = encrypter.choose() if choice is not "": break if choice == "1": # Runs Encode Game s = encrypter.rand_int() hint = encrypter.shift("anirban", s) with encrypter.lock: subprocess.call( ["espeak", " If anirban is encoded as " + str(hint)]) hint_str = "" for h in hint: hint_str = hint_str + h message("anirban -> " + hint_str, white, display_width / 4, display_height / 4, 30) pygame.display.update() encode = encrypter.shift(random_word, s) with encrypter.lock: subprocess.call(["espeak", " Then encode " + random_word]) message(random_word + " ->" + " ?", white, display_width / 4, display_height / 3, 30) pygame.display.update() encode_str = "" for h in encode: encode_str = encode_str + h check(encode_str, choice) elif choice == "2": # Runs Decode Game s = encrypter.rand_int() hint = encrypter.shift("anirban", s) hint_str = "" for h in hint: hint_str = hint_str + h with encrypter.lock: subprocess.call( ["espeak", " If " + str(hint) + "is decoded as anirban"]) message(hint_str + " -> anirban", white, display_width / 4, display_height / 4, 30) pygame.display.update() encode = encrypter.shift(random_word, s) with encrypter.lock: subprocess.call(["espeak", " Then decode " + str(encode)]) encode_str = "" for h in encode: encode_str = encode_str + h message(encode_str + " ->" + " ?", white, display_width / 4, display_height / 3, 30) pygame.display.update() check(random_word, choice) elif choice == "3": # Runs Guessing Game to guess the shifting key for arriving at the correct answer e = "" s = encrypter.rand_int() encode = encrypter.shift(random_word, s) encode_str = "" for p in encode: encode_str = encode_str + p subprocess.call([ "espeak", " Guess the shifting key if " + random_word + " is encoded as " + encode_str ]) message(random_word + "->" + encode_str, white, display_width / 4, display_height / 4, 40) pygame.display.update() message("SHIFTED WORD " + random_word.upper(), white, display_width / 2, display_height / 2, 40, True) pygame.display.update() m = "SHIFTED WORD " + random_word.upper() for k in range(10): subprocess.call(["espeak", str(10 - k) + " trials left"]) with encrypter.lock: rec = recorder.Recorder("../../../Language_Models/", "../../../Acoustic_Models/", L_LIB="num", A_LIB="en-us", TRIALS=1, DECODE=True, SILENCE=1) rec.start() r = open('./test.hyp', 'r') arr = r.read().split(" ") num = arr[0] r.close() try: e = encrypter.shift(random_word, int(num)) except Exception as z: print(z) message(m.upper(), black, display_width / 2, display_height / 2, 40, True, black) pygame.display.update() e_str = "" for p in e: e_str = e_str + p message("SHIFTED WORD " + e_str.upper(), white, display_width / 2, display_height / 2, 40, True) pygame.display.update() m = "SHIFTED WORD " + e_str.upper() if e_str == encode_str: subprocess.call(["espeak", "-s", "120", " Good!"]) break elif k == 9: subprocess.call([ "espeak", "-s", "120", " No you are wrong...the answer will be " + str(s) ]) message("Answer-> " + str(s), red, display_width / 2, (3 * display_height) / 4, 45, True) pygame.display.update() k += 1 message( "Score out of 10: " + str(encrypter.score(trials=k, choice=choice)), green, display_width / 2, (5 * display_height) / 6, 40, True) pygame.display.update() else: message("Wrong Choice", red, display_width / 2, display_height / 2, 45, True) pygame.display.update() gameExit = True clock.tick(20) subprocess.call([ "espeak", "-s", "125", " Options are 1: Resume and 2: Start another game" ]) pygame.quit() quit()
import sys sys.path.insert(0, "../../") from API import recorder, edit import threading lock = threading.Lock() with lock: record = recorder.Recorder("../../Language_Models/", DECODE=True, TRANSCRIBE=True, OUTPUT_SHELL="./lock.sh") record.start()
def main(): ''' The main block of the program which runs the entire display. ''' pygame.init() # Initialize pygame hangman = Hangman.Hangman() global m m = "" while True: try: random_word = hangman.rand() break except Exception as e: print(e) white = (255, 255, 255) red = (255, 0, 0) black = (0, 0, 0) blue = (0, 0, 255) green = (0, 255, 0) global gameDisplay gameDisplay = pygame.display.set_mode( (800, 600)) # Pass a tuple as a parameter display_width = 800 display_height = 600 pygame.display.set_caption("Hangman") pygame.display.update() # Update the specific modification clock = pygame.time.Clock() gameExit = False while not gameExit: message("Hangman", blue, display_width / 7, display_height / 7, 50) pygame.display.update() message("Deduce the word...", white, display_width / 4, display_height / 4, 30) pygame.display.update() subprocess.call(["espeak", "Deduce the word"]) hangman.str1 = hangman.initialize(random_word) message(hangman.str1, white, display_width / 2, display_height / 2, 40, True) pygame.display.update() m = hangman.str1 hangman.str1 = "" while hangman.counter < 20: subprocess.call( ["espeak", str(20 - hangman.counter) + " trials left"]) hangman.counter = hangman.counter + 1 hangman.str1 = "" letter = "" print("Enter letter: ") with hangman.lock: record = recorder.Recorder("../../../Language_Models/", LIB_FILE="characters", SILENCE=1, TRIALS=1, DECODE=True) record.start() r = open('./test.hyp', 'r') arr = r.read().split(" ") letter = arr[0] print(letter) lt = letter.lower() r.close() try: hangman.string = str( hangman.check(hangman.str1, lt, random_word)) except Exception as e: print(e) hangman.str1 = "" for j in range(0, len(hangman.string)): hangman.str1 = hangman.str1 + hangman.string[j] + " " message(m, black, display_width / 2, display_height / 2, 40, True, black) pygame.display.update() message(hangman.str1, white, display_width / 2, display_height / 2, 40, True) pygame.display.update() m = hangman.str1 if hangman.string == random_word: message("You Win", green, display_width / 2, (3 * display_height) / 4, 45, True) pygame.display.update() subprocess.call(["espeak", "You win"]) gameExit = True break elif hangman.counter == 20: subprocess.call(["espeak", "You lose"]) with hangman.lock: subprocess.call(["espeak", "The answer is " + random_word]) message("You Lose...Answer is: " + random_word, red, display_width / 2, (3 * display_height) / 4, 45, True) pygame.display.update() gameExit = True message( "Score out of 10: " + str(hangman.score(hangman.string, random_word)), green, display_width / 2, (5 * display_height) / 6, 40, True) pygame.display.update() clock.tick(20) subprocess.call([ "espeak", "-s", "125", " Options are 1: Resume and 2: Start another game" ]) pygame.quit() quit()
import sys sys.path.insert(0, "../../") from API import recorder, edit record = recorder.Recorder("../../Language_Models/", LIB_FILE="commands", DECODE=True, OUTPUT_SHELL="./launch.sh") record.start()