Welcome to Modern Speak and Spell’s documentation!

Speech Procesing API

This script can be used and the functions can be imported and used in almost any game and game_launcher so that if anything has to changed in this script...no change has to be done in the game code.

API package

API.edit module

Helps in editing the fileids and transcription files for decoding of recorded speech.

API.edit.fileids(n)

Function to edit test.fileids.

API.edit.transcription(n)

Function to edit test.transcription.

API.recorder module

This basically is a generalized recording and decoding module which can be used in all the game launching, gaming, as well as for testing speech and processing.

class API.recorder.Recorder(DEFAULT_LM_PATH, DEFAULT_AM_PATH, CHANNELS=1, RATE=16000, CHUNK_SIZE=1024, MIN_VOLUME=1600, OUTPUT_DIR='wav', SILENCE=3, TRIALS=None, MULTI=False, DECODE=False, L_LIB=None, A_LIB=None, TRANSCRIBE=False, OUTPUT_SHELL=None)

Bases: object

decoder()

Function to decode using the pocketsphinx batch command.

listen(stopped, q)

Function which listens to the audio stream and puts the chunks in a queue to be operated later on.

Parameters:
  • stopped – The threading event flag.
  • q – A queue to put all the required chunks into so that they can be processed later.
record(stopped, q)

Function which records when volume of a chunk is greater than a particular threshold value.

Parameters:
  • stopped – Same as in listen()
  • q – Same as in listen()
set_library(lmpath, ampath)

Function which sets the library paths in order to make it easy for every user to use.

Parameters:
  • lmpath – It contains the default language model path.
  • ampath – It contains the default acoustic model path.
start()

Main function which starts the entire process.

Spell It

This is a very simple game...a game in which the user has to spell a word given out and based on whether the word is spelt correct or wrong the results are generated accordingly.

Spell_It module

Main program...takes out words at random from the wordlist and asks to spell them out. It can be used to play the terminal version of the game.

This is the improvised Spell_It game

class Spell_It.Spell

Bases: object

rand()

Generates a random word from Wordlist.csv

score(output, word)

Finds out the user’s score after comparing with the original word.

Parameters:
  • output – The part of the word formed due to user input.
  • word – The original word.
Returns:

The user’s score out of 10

terminal(word)

Main function to take care of the whole process

Parameters:word – Takes the randomly generated word from rand() as input parameter.
test(string, w)

Function to take the recording and check if it matches with the letters.

Parameters:
  • string – The string to be formed as the result.
  • w – The specific letter to be checked.
Returns:

Returns string, improvised by the function itself.

Spell_gui module

Generates GUI using pygame, for Spell It!, using core functionality from Spell_It.py script.

Spell_gui.main()

The main block of the program which runs the entire display.

Spell_gui.message(msg, color, width, height, font_size, center=False, bg=None)

Function to display a specific message in a specific position with a specific color.

Parameters:
  • msg – The text to be displayed.
  • color – The font color.
  • width – The horizontal position of the text on the screen.
  • height – The vertical position of the text on the screen.
  • font_size – The font size of the text.
  • center – Boolean value to determine if text will be aligned to the center or not.
  • bg – Sets the background colour of the text on the window. Default value is None.

Hangman

This is a very simple game...a game in which the user has to fill in the blanks given to generate a specific word in a limited number of trials.

Hangman-Examples

This basic example is mainly to show how to play the game. Suppose the word is “ANIRBAN”

STEPS:
INPUT OUTPUT REASON
A A—-A- A is there two times
B A—BA- B is there one time
C A—BA- C is not present there
I A-I-BA- I is there one time
N ANI-BAN N is there two times
R ANIRBAN R is there one time

Strategy -> Start by spelling the vowels first...they are almost indispensible in every word...and can help in guessing the given word.

Hangman module

Updated Version of Hangman Game

class Hangman.Hangman

Bases: object

check(str1, l, r)

Function to check if input letter is present anywhere in the word

Parameters:
  • str1 – To compute the updated string.
  • l – The input letter.
  • r – The word generated using rand().
Returns:

The updated word after insertion of the input letter, if present in the actual word.

initialize(r)

Displays the word in form of dashes.

Parameters:r – Random word generated.
rand()

Generates a random word from Wordlist.csv

score(output, word)

Finds out the user’s score after comparing with the original word.

Parameters:
  • output – The part of the word formed due to user input.
  • word – The original word.
Returns:

The user’s score out of 10

terminal(word)

Calls the other functions to run the entire terminal version of the game.

Parameters:word – The word which is generated randomly using function rand()

Hangman_gui module

Hangman_gui.main()

The main block of the program which runs the entire display.

Hangman_gui.message(msg, color, width, height, font_size, center=False, bg=None)

Function to display a specific message in a specific position with a specific color.

Parameters:
  • msg – The text to be displayed.
  • color – The font color.
  • width – The horizontal position of the text on the screen.
  • height – The vertical position of the text on the screen.
  • font_size – The font size of the text.
  • center – Boolean value to determine if text will be aligned to the center or not.
  • bg – Sets the background colour of the text on the window. Default value is None.

Encrypter

This is a game in which the user will be given three choices. 1.Encode 2.Decode 3.Guess

In the first two games the user will be given to encode or decode some words based on a hint provided. In the third game, the user has to guess the actual word from the encrypted one using some shift operations.

Encrypter-Examples

The basic examples are mainly to show how to play the game.

A Note on the Caeser Cipher

This is a very simple cipher used in encryptions in which the letters are shifted each by a specific value.

Let us for example shift “ABXY” by 4:

A -> E, B -> F, X -> B, Y -> C, the encrypted word is “EFBC”.

Encode

The game is basically to encrypt a given word.

Suppose “anirban” is encrypted as “bojscbo”, so the shifting key is +1. Therefore suppose we have been given to encrypt “google”, so the encryption will be “hpphmf”. We just have to guess the encrypted word and spell it properly within 20 trials.

Decode

This game is basically to decrypt a given encoded word.

Suppose “cpktdcp” is decoded as “anirban”, the shifting key for decoding is -2. Therefore suppose we have been given to decode “eqy”, the answer will be “cow”. Just guess the word, and spell it out within 20 trials.

Guess

This is a rather interesting game, here we have to guess the shifting key. We will be provided the encoded word, the original word, and just guess the shifting key. Suppose the words given are “anirban” and “cpktdcp”, the shifting key for encoding is 2. So just enter the correct shifting key within 10 trials.

Encrypter module

class Encrypter.Encrypter

Bases: object

check(word)

The number of trials being 20, the user is allowed to try to encrypt or decrypt the given word correctly.

Parameters:word – Takes the randomly generated word from rand_word() as input parameter.
choose()

Module to help take the user input for the chosen option. The valid inputs are 1, 2 and 3.

rand_int()

Picks up a random integer between 1 and 25, including both.

rand_word()

Generates a random word from Wordlist.csv

score(output=None, word=None, trials=0, choice=None)

Finds out the user’s score after comparing with the original word.

Parameters:
  • output – The part of the word formed due to user input.
  • word – The original word.
  • trials – The number of trials taken to get to the right answer.
  • choice – The gaming option chosen as user-input.
Returns:

The user’s score out of 10

shift(word, n)

Used to shift each letter in a word by n...in order to encrypt or decrypt the word...the sequence is cyclic...that is a to z and then back to a.

Parameters:
  • word – The word to be encrypted or decrypted.
  • n – The shifting key.
Returns:

The word with all the letters shifted, as a list type value.

terminal(choice, random_word)

Main module to run the entire game in terminal

Parameters:
  • choice – Choice 1, 2 or 3 as user input.
  • random_word – Random word generated using rand_word()
test(string, w)

Function to take the recording and check if it matches with the letters.

Parameters:
  • string – The string to be formed as the result.
  • w – The specific letter to be checked.
Returns:

Returns string, improvised by the function itself.

Encrypter_gui module

Generates Pygame GUI for the Encrypter game.

Encrypter_gui.check(word, choice)

Performs the same function as that of check() function of class Encrypter..except that the messages are displayed to the GUI rather than being printed out to the console.

Parameters:word – The input word to be operated on.
Encrypter_gui.main()

The main block of the program which runs the entire display.

Encrypter_gui.message(msg, color, width, height, font_size, center=False, bg=None)

Function to display a specific message in a specific position with a specific color.

Parameters:
  • msg – The text to be displayed.
  • color – The font color.
  • width – The horizontal position of the text on the screen.
  • height – The vertical position of the text on the screen.
  • font_size – The font size of the text.
  • center – Boolean value to determine if text will be aligned to the center or not.
  • bg – Sets the background colour of the text on the window. Default value is None.

Crossword

This game has been built as an extension of Hangman. The game has only been designed to fit for 4x4 matrices with 4 words, randomly generated from the wordlist. It can be extended to other general cases in the future.

Crossword module

Crossword.find(w, c, r)

This function helps to find if there is an intersection between the c’th letter of a word and the r’th letter of another word given in the file.

Parameters:
  • w – The word provided.
  • c – The index of the letter of the required word.
  • r – The index of the letter of the given word.
Returns:

The word whose letter matches with the letter of the given word.

Crossword.find_inv(x, y, p)

This function helps to find out a word, whose two letters at two specified positions are x and y.

Parameters:
  • x – The letter at the beginning position.
  • y – The letter at the beginning position.
Returns:

The word found out from the list.

Crossword.main()

Uses the functions to generate 4 4-letter words for a 4 X 4 crossword.

maker1 module

class maker1.Crossword

Bases: object

assign_meaning()

Appends the meanings to a list.

check(str1, l, w)

Checks if letter is present in word or not.

Parameters:
  • str1 – Variable to return the updated string.
  • l – The letter itself...as user-input.
  • w – The string to be checked.
Returns:

The updated string.

display(color)

This function displays the crossword matrix at each stage of the game, on the pygame window.

Parameters:color – The color to be displayed.
formation(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.

Parameters:
  • w – The qth word generated from Crossword script.
  • q – The index of the word.
Returns:

The updated string if within game-running time, or else returns “END”.

meaning(w)

Extracts the meaning out of the line containing the word.

Parameters:w – The word for which meaning has to be found out.
Returns:The meaning of the word concerned.
message(msg, color, width, height, font_size, center=False, bg=None)

Function to display a specific message in a specific position with a specific color.

Parameters:
  • msg – The text to be displayed.
  • color – The font color.
  • width – The horizontal position of the text on the screen.
  • height – The vertical position of the text on the screen.
  • font_size – The font size of the text.
  • center – Boolean value to determine if text will be aligned to the center or not.
  • bg – The background colour of the text. Default value is None.
multi_line_text(surface, text, pos, font_size, color, bg=None)

Used to display multi_line text.

Parameters:
  • surface – The game display surface or window.
  • text – The single(or multi-line)text to be displayed.
  • pos – The width and height positions of the text, to be entered in tuple format.
  • font_size – The display font_size of the text.
  • color – The color of the text to be displayed on screen.
  • bg – The background colour of the text. Default value is None.
maker1.main()

Main function to launch the pygame GUI, and use the other functions to build the game sequence.

Design of the game structure

The positions of the words in the rows and columns can be 1-3 and 2-4 respectively, and words are designed to be fitted in the crossword alternately, means if a word is at the first row, then the next word will be at the third row, and same logic for the columns.

The matrix is displayed according to the following logic. |#| for the blank cells, and |A| for the cell with letter A.

The 4-letter words have been scraped out of the wordlist. Then using PyDictionary, it’s meanings, in noun, verb, adjective, and adverb forms have been formed, and combined list is in words.csv.

The game has been designed to give the user a hint, by displaying the meaning of the word, before he guesses the word.