Dyslexic DEV? No problem!
Tags: linux, productivity, a11y, voice
Published: 2021-10-31 22:06:33

## Given 

 that I am dyslexic and also suffer from [**aphantasia**][link_pnts], which is a fascinating quirk of the brain, one  can imagine I have sort of a **love / hate** relationship with reading. 

On the one hand, I must keep up with the news and trends of the software engineering industry but the serious and useful information I require, is in written form and that always drains my `reading battery` because of the above average amount of concentration I have to put forward.

## When

 daylight saving Weekend rolled around, I decided to do something useful with the "additional" hour, so I set out to improve this situation for people like me. 

 I decided to build something that allows us to take the text from `any article` in `any language` (English, German, Romanian in my case) and convert it to an `mp3` file so that we can "listen to the article" and not drain our weak `reading battery`.

## Then

 I remembered one of the most important [**UNIX** principles][link_nx_prncpl]: 

> *"DO ONE THING AND DO IT WELL"* 

so I challenged myself to: 

- use `WELL DONE` existing `THINGS`
- write only a shell script 
- have less than 31 lines (today is halloween 🎃 )
- uses only `cli tools`,`pipes`, `shell commands` 
- time box of `1h`. 

## 🤪

I did it! But this was only possible because so many wonderful people have developed so many great projects and shared them with the rest of us. There exists a multitude of software out there and any UNIX based OS allows us to interconnect it seamlessly, simply amazing 🤩

## Result

### The script: 
```shell 
#!/bin/sh
# this script does some text editing for the:
#   $1 - input file
# and stores it into the:
#   out-$1 - output file
# which it then later utilises to CURL to http://localhost:5002/api/tts running:
#   docker run -it -p 5002:5002 synesthesiam/mozillatts:en
# you can replace the TAG at the end with any language supported by TTS
# it will:
#  - produce a .wav file for each sentance in the outputfile
#  - join the wav files into a single one
#  - turn it into a .mp3 file named audio-$1.mp3

cat "$1" | awk -F'\.' '{ for (i=1; i<NF; i++) print $i ".\n" }' | tr "'" "´" |tr "\"" "´" > out-"$1"

input="out-$1"
while IFS= read -r line
do
  curl --location --request POST 'http://localhost:5002/api/tts' --header 'Content-Type: text/plain' --data-raw "$line" -o "audio_$(date +%s).wav"
done < "$input"

ls audio*wav |awk '{print "file " $0}' > wav-list.txt

ffmpeg -f concat -safe 0 -i wav-list.txt -vn -ar 44100 -ac 2 -b:a 128k audio-$1.mp3

rm out-$1
rm *wav
rm wav-list.txt

open "audio-$1.mp3"
```

### The list of ingredients: 

1. [Mozilla/TTS][tts]
1. [FFMPEG cli][ffmpg] this thing went to [Mars 🔴][mrs]
1. UNIX based OS
1. docker cli
1. the above script

### The "recipe": 
```shell
 # in your terminal run: 
 docker run -it -p 5002:5002 synesthesiam/mozillatts:en
 # replace the 'en' tag with 'de', 'fr', 'ro' etc.
 # select and copy the text you want to listen to 
 # paste it into a file: `article.txt`
 # save the script as `audiofy.sh` next to the text file
 # in the terminal run:
 sh audiofy.sh article.txt
```
### Demo

I used a snippet from the README file of the fantastic [Mozilla/TTS][tts] for my demo i.e:

![Mozilla TTL README snippet][fixed-read]

Have a listen to the output on [soundcloud][snd-cld]. (use the `open in new tab` function so you can see the text and marvel at the `natural sounding` synthetic voice)  

## Conclusion

Even tough I set only `1h` for this project, I do love the result and will return to it for improvements. Implementing this was way too much fun. 

Also in the time I wrote this post I listend to most of the news articles that popped up on my Google News feed, because I had converted them as a test for my script. 

Synergy: **achieved**!
Productivity: **increased**! 
Reading battery: **protected**! 

## ✌️ 
 
[link_pnts]:https://aphantasia.com/making-aphantasia-better-known/
[link_nx_prncpl]:https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well
[ffmpg]:https://github.com/FFmpeg/FFmpeg
[tts]:https://github.com/mozilla/TTS
[mrs]:https://link.springer.com/article/10.1007/s11214-020-00765-9#Sec45
[audio-demo]:https://soundcloud.com/viorel-petcu-439304880/tts-demo?si=fa7479d4961a4562b2cef15a7a8a70eb
[fixed-read]:https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqdyxx8748t7gubh11xv.png
[icon]:https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tmghrqno50n7xyo2g6m7.png
[snd-cld]:https://soundcloud.com/viorel-petcu-439304880/tts-demo