A Convincing Text to Handwriting Converter

Shantanu Verma
GDSC VIT Vellore
Published in
4 min readAug 5, 2020

Did you know that an average person’s handwriting speed is 13 words per minute, and their typing speed is 3 times greater?

I am an average person, and I’ve found the experience of handwritten work to be awful if there is a lot of work to be done. Too much writing takes too long. It makes you focus less on what you’re writing, and instead you paint letters on a page perfunctorily.

So what to do when faced with unreasonably extensive work? Pine away at your notebook for hours, writing stuff you could write in a text editor in a fraction of the time?

As a student of the software engineering discipline, I say we automate it!

HandWriter

HandWriter is an open source application that does just this. To the end user, the application is a black box that takes as input a .docx file, and throws as output a PDF file with the text converted to handwriting.

HandWriter is available as a desktop package for macOS, Windows, and Linux, complete with installers. You can get it here.

Here is a sample of the results achieved with HandWriter -

How it does this

HandWriter was built with the goal of achieving convincing results in mind.

Before going into how HandWriter does what it does, let’s analyse solutions to this problem from scratch and discuss how each approach fits our requirement.

  • Fonts?

A font based approach leverages existing document editors and simply feeds them a font of your handwriting. Such a font can be generated easily by using online tools.

Clearly, this is a very simple approach, because document editors (such as Word) do all the heavy lifting for you and your job is simply to generate a font for your handwriting and feed it to them.

However, this approach falls short of the first requirement — achieving convincing results. This is because a document editor requires a consistent representation of each letter, and that’s simply not how people write. The consistency of the output reveals its machine generated nature.

  • Machine Learning?

A machine learning approach would solve the problem of random letter generation, at the cost of increased complexity. This is because a text editor is no longer involved, and therefore arranging every letter, word and line correctly in space falls on us. Think of an encoder-decoder which generates inconsistent images of a letter. We would then have to stack these images in a spatially correct fashion to get the results we want.

In this approach, there is a lack of determinism in the final outcome (which is a consequence of the randomness this solution introduces). If you’re not careful, the outcome might be too indeterminate to handle comfortably, especially since spatial arrangement falls on us.

  • Abstraction.

The encoder-decoder approach can be thought of as an abstraction — a model that takes a letter as input and throws its handwritten image as output.

This is a crucial idea, because you can replace this encoder-decoder by a hash table that throws out static images of a letter, and you maintain the same abstraction. Randomization can be achieved with multiple samples of every letter in the hash table, and you would pick one sample randomly.

This is where Occam’s Razor comes in — given both Machine Learning and Abstraction approaches suffice equally for our requirement, we pick the simpler one. Therefore HandWriter uses the simpler approach of abstraction.

HandWriter’s Abstractions

  • Letter Parser — This is our hash table. Converts letter text to image directly. Spatial arrangement of a letter is handled here.
  • LineParser — Responsible for converting a line of text to handwritten output word by word, and wrapping leftover text to next line.
  • PageParser — Responsible for compiling lines into a page, padding pages with whitespace, and wrapping leftover lines to next page.
  • DocumentParser — Responsible for compiling pages into a document.

Contributing

HandWriter is an open source project, and you can contribute! Check it out here.

Conclusion

HandWriter successfully delivers on its basic premise. At the time of this writing it only does so for a static handwriting sample. The goal for future implementations is to allow a user to feed samples of their own handwriting and use those instead (this is where Machine Learning would come in).

And it does what it does well! It’s saved me hours of time and a lot of effort personally.

So give it a spin, and let me know what you think. :)

Links

--

--