Python Speed Reader Implementation (4 steps)

When you become an engineer, and I mean not just by studying it in college but by experiencing it through daily life, inventions, nature and science fewer and fewer things will faze you.

It’s also similar to what Elon Musk quoted the other day:

“All of physics is either impossible or trivial. It is impossible until you understand it, and then it becomes trivial.” E Rutherford

So here is a very simple Python script that gives an idea about how all those professional speed reading software out there might be created.

It may be interesting for someone who is keen on speed reading or improving reading as a skill. Some people also like to ponder what they read.

I see benefit in both styles although I lean to the latter most of the time.

Even if you’re not after speed reading this is a great demonstration to expand a beginner Python programmer’s horizons about how real life applications and software can depend on a tiny simple script that you are also capable of creating.

We can achieve this Python script in 3 simple steps:

  1. importing libraries: win32com.client module will be useful to create a connection to Notepad App in Windows and then send keys to it.
  2. win32com.client : We’ll use .Dispatch method to create a connection to Windows COM interface.Then we’ll use 2 methods with the shell we’re creating:
    • .Run: to run Notepad
    • .AppActivate: to make sure Notepad is the active window while sending keyboard keys.
  3. message: Just any message will do, this is what will be written at a predefined pace on your screen. So, ideally something you’d like to read.
  4. loop: This is likely the most interesting part from the programming sense. We’ll create a loop that loops through the message and sends each character with a predefined delay. By adjusting this delay variable you can make the text or script appear slower or faster to your liking and needs.

Python Tutorial (via win32com.clent and time libraries)

Step 1: Importing libraries

import win32com.client
import time

Step 2: Initializing shell connection using win32com.client.Dispatch("WScriptShell")

We’re also using .sleep() method from time library to create a little bit of a delay so that input from Python isn’t too fast for Windows to execute in correct order.

shell = win32com.client.Dispatch("WScript.Shell")
shell.Run("notepad")
time.sleep(1)
shell.AppActivate("Notepad")

Step 3: This is straightforward. Just some nice message to read on the screen.

msg="""Hello World 


elena@****.com
12:50 PM : 10 minutes ago
to me

To create is to recombine’ said the molecular biologist Francois Jacob. Imagine if the man who
invented the railway and the man who invented the locomotive could never meet or speak to each other, 
even through third parties. Paper and the printing press, the internet and the mobile phone, 
coal and turbines, copper and tin, the wheel and steel, software and hardware. I shall argue 
that there was a point in human pre-history when big-brained, cultural, learning people for the 
first time began to exchange things with each other, and that once they started doing so, 
culture suddenly became cumulative, and the great headlong experiment of human economic ‘progress’ 
began. Exchange is to cultural evolution as sex is to biological evolution.

From The Rational Optimist
by Matt Ridley
"""

Step 4: Finally, the loop. It’s a simple loop that does two things:

  1. Create a time delay between sending each character.
  2. .SendKeys() method is used to send each character to Notepad as a key.

delay here is expressed in seconds.

delay=0.04
for i in msg:
    time.sleep(delay)
    shell.SendKeys(i, 0)

Additionally, you can also come up with a negatively correlated structure and call it pace. For example:

pace =1
if pace == 1:
    delay = 1
elif pace == 2:
    delay = 0.5
elif pace == 3:
    delay = 0.025

and so on. Something like that. This is what happens with consumer products. Since dealing with microseconds can be alienating to the general public. Parameters are usually prettified and made more presentable.

Let’s continue without the pace implementation though to keep things simple.

Full Code (Speed Reader Script Using Python to Send Keys)

So, here is the full code:

import time
import win32com.client

###Shell Connection
shell = win32com.client.Dispatch("WScript.Shell")
shell.Run("notepad")
time.sleep(1)
shell.AppActivate("Notepad")

###Message
msg="""Hello World 


elena@****.com
12:50 PM : 10 minutes ago
to me

To create is to recombine’ said the molecular biologist Francois Jacob. Imagine if the man who invented the railway and the man who invented the locomotive could never meet or speak to each other, even through third parties. Paper and the printing press, the internet and the mobile phone, coal and turbines, copper and tin, the wheel and steel, software and hardware. I shall argue that there was a point in human pre-history when big-brained, cultural, learning people for the first time began to exchange things with each other, and that once they started doing so, culture suddenly became cumulative, and the great headlong experiment of human economic ‘progress’ began. Exchange is to cultural evolution as sex is to biological evolution.

From The Rational Optimist
by Matt Ridley
"""  

###For Loop for sending characters in sequence with a delay
delay=0.04
for i in msg:
    time.sleep(delay)
    shell.SendKeys(i, 0)

And the result should be something like this:

Closing Thoughts (Application Opportunities and Thank You)

Thank you for checking out this scripting tutorial with Python. If you’re like me you’re also going to enjoy how straightforward this little script is. It’s simple and plain-vanilla but it’s still quite impressive. I imagine this is something that’d be also useful for:

  • Creating self-reminders
  • Training reading skills
  • Preparing demos, tutorials, blog content etc.
  • Living a James Bond fantasy (make sure the message destroys itself.)
  • Understanding software markets and commercial thinking
  • Packaging another program you’ve created.
  • Presentations.
  • Just practicing loops in Python
  • Jokes and pranks with your non-techy buddies.

Please share with appropriate reference to HolyPython.com if you enjoyed this tutorial, so your community can also benefit from it.

Thanks for visiting.

Arrivederci!

Recommended Posts