import pyttsx3 engine = pyttsx3.init() engine.setProperty("rate", 100) keys = { "2": "abc", "3": "def", "4": "ghi", "5": "jkl", "6": "mno", "7": "pqrs", "8": "tuv", "9": "wxyz", "0": " ", } numbers_spoken = [ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", ] def keypad_encode(text): orig_message = text.lower() keypad_strokes = [] for i in orig_message: strokes = _to_stroke(i) if strokes: keypad_strokes.append(strokes) coded = " ".join(keypad_strokes) coded_ns = coded.replace(" ", "") coded_arr = list(coded_ns) numbers = [] for x in coded_arr: numbers.append(numbers_spoken[int(x)]) return numbers def _to_stroke(char): for i in keys: if char in keys[i]: return i * (keys[i].find(char) + 1) return None def transmit(msg): emsg = keypad_encode(msg) print(emsg) for number in emsg: engine.say(number) engine.runAndWait()