Communication is fundamental to human connection, but for many people, speaking or typing isn’t even possible. I wanted to create a simple tool that could help those who cannot communicate by allowing them to speak using only one finger and some simple keyboard inputs.
My goal was not to build a commercial product but to demonstrate that anyone, even without extensive programming experience, can create helpful tools with the support of AI and accessible coding libraries.
This project shows how a clear problem, combined with basic programming and AI guidance, can lead to a functional communication tool for people who might otherwise struggle to express themselves.
How I Built Tap-to-Morse Keys Using Python and AI
This program lets users communicate by tapping arrow keys:
Left for dot (.)
Right for dash (-)
Up once to end a letter
Up twice quickly to end a word
Down to read the phrase aloud
Space to delete the last dot/dash
It uses Morse code to translate these taps into letters, words, and phrases, then speaks them out loud. Here’s the code with detailed explanations.
1. Imports and Setup
import pyttsx3
import keyboard
import time
pyttsx3: Text-to-speech engine to vocalize the decoded phrase.
keyboard: To detect arrow key presses in real-time.
time: To measure intervals between key presses, especially for double-tap detection.
2. Morse Code Dictionary
morse_dict = {
'.-': 'A', '-...': 'B', '-.-.': 'C', '-..': 'D', '.': 'E',
'..-.': 'F', '--.': 'G', '....': 'H', '..': 'I', '.---': 'J',
'-.-': 'K', '.-..': 'L', '--': 'M', '-.': 'N', '---': 'O',
'.--.': 'P', '--.-': 'Q', '.-.': 'R', '...': 'S', '-': 'T',
'..-': 'U', '...-': 'V', '.--': 'W', '-..-': 'X', '-.--': 'Y',
'--..': 'Z', '-----': '0', '.----': '1', '..---': '2',
'...--': '3', '....-': '4', '.....': '5', '-....': '6',
'--...': '7', '---..': '8', '----.': '9'
}
Maps dots and dashes to letters and numbers for translation.
The program looks up user input sequences here to find the matching character.
3. Initialize Text-to-Speech and Variables
engine = pyttsx3.init()
engine.setProperty('rate', 150)
current_morse = ''
current_word = ''
phrase = ''
previous_key = ''
last_up_time = 0
Initializes the speech engine and sets a comfortable speaking rate.
Variables track input:
current_morse: holds the dot/dash sequence of the current letter.
current_word: the letters collected to form a word.
phrase: the complete phrase built from multiple words.
previous_key prevents repeated inputs from a held key.
last_up_time helps detect if the up arrow is pressed once or twice quickly.
4. Display Controls to the User
print("Controls:")
print("← = Dot | → = Dash | ↑ (once) = End Letter | ↑ (twice) = End Word")
print("↓ = Read Phrase | Space = Delete Last Dot/Dash")
print("-" * 50)
Simple instructions to guide how to use the program.
Shows which arrow corresponds to each Morse code input or control command.
5. Listening for Dot Input (Left Arrow)
while True:
if keyboard.is_pressed('left'):
if previous_key != 'left':
current_morse += '.'
print(f"Dot (.) | Morse: {current_morse}")
previous_key = 'left'
time.sleep(0.2)
Detects Left arrow press adds a dot (.) to the current letter’s Morse code.
Prints the current Morse code for feedback.
Sleeps briefly to avoid multiple counts from a single key hold.
6. Listening for Dash Input (Right Arrow)
elif keyboard.is_pressed('right'):
if previous_key != 'right':
current_morse += '-'
print(f"Dash (-) | Morse: {current_morse}")
previous_key = 'right'
time.sleep(0.2)
Detects Right arrow, adds a dash (-).
Provides feedback similarly to dot input.
7. Deleting Last Dot/Dash (Space Bar)
elif keyboard.is_pressed('space'):
if previous_key != 'space':
if current_morse:
print(f"Deleted: {current_morse[-1]}")
current_morse = current_morse[:-1]
print(f"Current Morse: {current_morse}")
else:
print("Nothing to delete.")
previous_key = 'space'
time.sleep(0.2)
Deletes the last input symbol (dot or dash) in the current Morse letter.
Helpful for correcting mistakes before ending a letter.
8. Ending Letters and Words (Up Arrow)
elif keyboard.is_pressed('up'):
if previous_key != 'up':
current_time = time.time()
if current_time - last_up_time < 1.0:
# Second up press within 1 second = end word
if current_morse:
letter = morse_dict.get(current_morse, '?')
current_word += letter
current_morse = ''
phrase += current_word + ' '
print(f"Word: {current_word}")
current_word = ''
else:
# First up press = end letter
if current_morse:
letter = morse_dict.get(current_morse, '?')
current_word += letter
print(f"Letter: {letter} | Word: {current_word}")
current_morse = ''
last_up_time = current_time
previous_key = 'up'
time.sleep(0.2)
First up press: finishes current letter, converts Morse to letter, and adds to current word.
Second up press (within 1 second): finishes current word, adds it plus a space to the phrase, then clears the current word buffer.
Prints feedback about letters and words to keep the user informed.
9. Reading Phrase Aloud (Down Arrow)
elif keyboard.is_pressed('down'):
if previous_key != 'down':
if current_morse:
letter = morse_dict.get(current_morse, '?')
current_word += letter
current_morse = ''
if current_word:
phrase += current_word
current_word = ''
if phrase.strip():
print(f"Phrase: {phrase.strip()}")
engine.say(phrase.strip())
engine.runAndWait()
phrase = ''
previous_key = 'down'
time.sleep(0.5)
Finalizes any unfinished letter or word.
Uses pyttsx3 to read the entire phrase aloud.
Resets the phrase to start fresh.
10. Resetting Key Detection
else:
previous_key = '' # Reset when no key pressed
Allows the program to detect new key presses after keys are released.
Final Thoughts
With just a few libraries and lines of code, I created a one-finger communication tool using AI-assisted coding. This project shows how anyone with curiosity and some help from AI can build tools that empower people with communication challenges.
If you want to help others or experiment with accessible tech, start small, use AI to guide you, and keep building. Tools like this can make a real difference.
The codes and .exe file. If you like to test or see the app yourself.