/ YOUTUBE2AUDIOBOOK

Continuously Listen to YouTube Audiobooks on Your Phone

An end-to-end solution for downloading any YouTube video as an audiobook and listening to it on your phone. While keeping track of playback positions. Even during app restarts and system reboots. Readily available as a Bash script on GitHub.

Update 2020-10-18: We are proud to announce that YouTube2­Audiobook is now also available on Docker Hub. Listen sooner. Leverage the Docker container.

In the spirit of Sellotape engineering, this article focuses on reusing existing components as much as possible and provides step-by-step instructions of how to achieve the goal by

  1. Downloading a YouTube video as an audiobook
  2. Transferring the audiobook to a mobile device
  3. Leveraging an audiobook app that keeps track of playback positions

For a concise step-by-step guide, see also Listen to YouTube.

The Wisdom of Generations Between Two Covers

I love books. And I very much respect books. With a substantial message.

It takes quite some time and effort to write a book that carries a substantial message. It’s fairly easy to combine some random words and make them available to the world (yes, this includes this blog as well).

An old saying has it that it’s fairly easy to write a best seller. All it takes is 1,000 monkeys and 1,000 typewriters. And 1,000 years. For the monkeys to randomly type away. The only problem is how to tell the best seller apart from the all other rubbish. And that’s only monkeys typing. Now, extrapolate that to humans.

Typewriters

So, how can we ensure quality control on a lengthier sequence of words between two covers?

In the end, it’s a rigorous scientific process of eliminating every possible logical error, mistake, or negligence in the content that sets random collections of words apart from what we regard as books.

Hence, while every care has been taken when writing this article, it still only is a blog post and not a book. I haven’t put this up for review yet. But you’re on it. Prove me wrong, and I’ll buy you a pint!

It used to be the case that whatever gets published between two covers had to undergo that rigorous scientific process before it was deemed to be worthy of hitting the printing press. And there was — and still — is a very good reason for that.

Why Books (Still) Matter

There’s something books provide that is hard to get elsewhere when it comes to quality of in-depth publications.

Books come with a guarantee. Someone wrote it. Someone else reviewed it. And someone else eventually printed and sold it. In this whole value chain, accountability matters. Get the content wrong and the consequences can reach from loss of reputation to loss of business.

But this accountability can also help build reputation and trust. Books were the visible result available to the masses at the end of a very long thought process. A way for substantial messages to reach millions. All throughout history, ideas have been placed on printing presses for them to leave their mark on history.

Printing Press

Books also contain the combined knowledge of millennia of human thoughts, research, or experience. From Sun Tzu to Socrates and Taleb. Books are the predominant way of how we pass the combined knowledge from generation to generation. The medium that delivers books to us might slightly change in the future but the concept of content with accountability still seems to have some life left in it.

However, I personally find that there’s a slight problem with books. At least in the traditional sense of a long sequence of words between two covers.

The Problem of Reading Books

The problem is simple.

It starts with me. I should read more. I know that.

After all, I’m highly interested in an ever growing number of books with a substantial message. From management and philosophy to finance. Yes, feel free to talk to me about a lot of things. Teach me something new and I’ll buy you a pint!

But the unpleasant truth is that those books just keep piling up on my desk as I struggle to find the time to read them. Every weekend, I plan on having a go at at least one of them. Every Sunday evening, I realise that I haven’t even looked at a single one of them. Not good. This keeps me dumb and unhappy. Especially dumb.

I need to make reading books part of my everyday life. In essence, I need a better way to scale reading books.

Sure, I could walk around reading a book, just like many other people prefer to stare at their phones. However, there’s a slight problem with that approach as well.

Printing Press

For starters, it would limit my attention. Either to the surrounding or the book. The first one can have catastrophic consequences and result in a serious accident — London is a busy city after all. The second one can result in a half hearted understanding of the book at best. I don’t really know what’s worse. All I know is that I don’t want either, to be honest.

The more pressing problem is that this approach still requires me to read the actual book. And when thinking about it, there’s not that much spare time in a day to fully focus on reading a book. So, I need another way.

A Scaleable Way of Reading Books

An honest assessment of my everyday life has shown me that I actually have plenty of spare time during the day to read books.

It’s just that this spare time likes to hide behind other activities that actually don’t require my full attention.

A simple example on a workday is my commute to and from work. I has become routine in a mere matter of days. I know the stations. I know the platforms. I know the times. I even know how to get a seat if I was up for that. And it’s not that I introduce a lot of variance into the remaining minutes of walking to my final destination either.

Tube Platform

So, in essence, I can manage to get to and from work pretty on much autopilot. But this then allows me to keep my brain busy and feed it with other things in the meantime. No, not reading books. Because of the thing with the accidents again. But there is another way.

In recent years audiobooks have become quite popular and more and more titles have been release as audiobooks as well. This is good news as audiobooks are a great way to scale the problem of reading books.

I can now cruise to work on autopilot while reading a book. Technically, someone else is reading it to me. The means of transporting the actual message is slightly different but the book is still the same. Finally, I have a scalable solution to reading books.

Audio Book

Great. Job done?! Well, conceptionally, yes. Now, on to the details. For starters, where to get those audiobooks? I do tend to spend a lot of time commuting, after all.

Audible?

There are great commercial offerings out there like Audible. They distribute and also produce an ever growing number of contemporary as well as classic audiobooks that can be purchased and listened to on mobile devices.

Audible also offers a free app for most platforms which allows to manage purchases and also remembers the playback position of each audiobook. Even through app restarts and system reboots.

YouTube!

However there’s an even bigger source of audiobooks. And most of them are free. You may have heard or even come across the service once or twice before. YouTube.

YouTube Screengrab

From TED talks to audiobooks recorded by enthusiasts, YouTube is home to a large selection of great material which is in the public domain.

However, YouTube is mainly a video streaming service. Which means there are two problems. Video. And Streaming.

It’s only been recently that videos can now be downloaded (rather than being forced to stream them) and watched without an active internet connection. Even with that in place, you are effectively still watching a video when listening to an audiobook. This can be a bit of a drain on screen as well as battery life.

So, watching audiobooks on YouTube sort of works. But there has to be a better way! And there is.

Downloading Audio from YouTube

Audiobooks do not necessarily have to contain video; they can just be regular Mp3 files. This makes them light on screen and battery life as well as universal to play back.

The first step in combining public domain material readily available on YouTube with the benefits of audiobooks is to download the audio section of a YouTube video as an audiobook.

At the end of this section, a new Mp3 file containing the audio section of a given YouTube link will be stored as an audiobook on the local machine.

This is the first step in an end-to-end solution that also includes transferring the downloaded audiobook to a phone and leveraging an app that keeps track of playback positions during app restarts and even system reboots.

YouTube2Audiobook

The repository https://github.com/dumrauf/youtube_to_audiobook contains a Bash script that downloads the audio section of a given YouTube link and converts it to an audiobook. The audiobook can then be used like any other Mp3 file.

You Have

Before you can use the Bash script in the repository out of the box, you need

youtube-dl which is a Python application that ships with a CLI and allows to download audio and video from YouTube (and “a few other sites” as well) — FFmpeg which is “a complete, cross-platform solution to record, convert and stream audio and video” (from https://ffmpeg.org/) and also ships with a CLI

Most likely, you also have a YouTube link that you want to convert to an audiobook.

Let’s use the below YouTube video, available at https://youtu.be/WRbalzuvms4, as an example throughout this article.

You Want

After running the Bash script in the repository you get an audiobook version of the input YouTube link stored on your device.

In the case of the above example, you get a new file called Return of Sherlock Holmes (version 2 Dramatic Reading) _ Sir Arthur Conan Doyle _ English _ 1_6-WRbalzuvms4.mp3 which contains an audiobook version of YouTube link https://youtu.be/WRbalzuvms4. Note that the YouTube identifier WRbalzuvms4 is part of the file name; the last section before the file extension to be precise.

Execution

The stand-alone Bash script yt2ab.sh is located in the root folder of the repository.

Getting Started

At minimum, the Bash script yt2ab.sh requires a YouTube URL to be passed in via the -u parameter.

The above example YouTube link https://youtu.be/WRbalzuvms4 can be converted into an audiobook via

./yt2ab.sh -u https://youtu.be/WRbalzuvms4

The Bash script then carries out two steps. It first downloads the audio section as well as a thumbnail of the given YouTube link using youtube-dl as shown below. YouTube2Audiobook — youtube-dl Screenshot

Depending on the size of the audio section in the given YouTube link and your connection speed, it may take several minutes before this step completes. Usually, this tends to be the quick part. And it’s also the part where a quick connection really pays off.

Afterwards, the script then converts the downloaded audio section to a standard Mp3 file using FFmpeg as show below. YouTube2Audiobook — FFmpeg Screenshot This ensures that the file can be easily played back on most devices. Plus, this step also adds the previously downloaded thumbnail to the Mp3 file for easier recognition. Convenience can be king.

Depending on the size of the audio section in the given YouTube link and the actual audio conversion speed of your machine, it may take several minutes before this step completes.

So, get yourself another cup of coffee or send the script to the background. However, the good news is that this is the last step and once complete, the Bash script successfully completes.

Advanced Use

Further options are available via additional CLI parameters. The full list of currently available parameters is

Usage  : yt2ab.sh -u <youtube-url>                -s [audio-speed] -q [audio-quality] -v(erbose)
Example: yt2ab.sh -u https://youtu.be/WRbalzuvms4
Example: yt2ab.sh -u https://youtu.be/WRbalzuvms4 -s 1.5
Example: yt2ab.sh -u https://youtu.be/WRbalzuvms4 -s 1.5           -q 3
Example: yt2ab.sh -u https://youtu.be/WRbalzuvms4 -s 1.5           -q 3               -v
Note: for audio quality see also column 'ffmpeg option' on <https://trac.ffmpeg.org/wiki/Encode/MP3>; defaults to 4

Controlling Audio Speed

The audio_speed parameter allows to increase or decrease the speed of the resulting audiobook; defaults to 1 and hence leaves the audio speed unchanged.

This setting is particularly helpful when trying to normalise the original speed of the given YouTube link in the resulting audiobook. In that case, set the audio_speed so that original speed x audio_speed = 1, i.e., if the original speed of the YouTube link is 1.5, choosing a value of 2/3 for audio_speed will normalise the speed of the resulting audiobook as 1.5 x 2/3 = 1.

However, the final audiobook may sound awkward as audio speed adjustments can be a lossy process.

Controlling Audio Quality

The audio_quality parameter allows to set the quality of the resulting audiobook; defaults to 4. Here, the values are derived from column “ffmpeg option” in table “LAME Bitrate Overview” on https://trac.ffmpeg.org/wiki/Encode/MP3.

Controlling Verbosity

The v(erbose) parameter increases the verbosity of the script and can be used for debugging purposes.

FAQs

Below is a list of frequently asked questions.

I Know How to Make This Better!

Excellent. Feel free to fork the repository, make the changes in your fork, and open a pull request so we can make things better for everyone. Thanks!

Transferring the Audiobook to a Mobile

At this point, the audiobook version of YouTube link https://youtu.be/WRbalzuvms4 is stored on the local machine. The Mp3 file still needs to be transferred to a mobile device where it can be listened to in an audiobook app that keeps track of playback positions. Even during app restarts and system reboots.

This section focuses on transferring the audiobook to a mobile device, using the solution described in article “Transfer Files to Your Mobile By Scanning a QR Code”.

Web-Serve-This-Directory

The repository https://github.com/dumrauf/web_serve_this_directory contains a Bash script that starts a Python web server with the current directory at its root.

In case qrencode can be detected, a QR code with the URL of the web server is also created. When scanning the QR code on a phone or tablet connected to the same network, it allows instant access to the local machine. This can save a lot of typing.

Starting the Web Server

The stand-alone Bash script web-serve-this-directory.sh is located in the root folder of the repository. The directory containing the audiobook can be served over HTTP on port 8000 via

./web-serve-this-directory.sh -p 8000

In case the local IP address is 192.168.1.176, this will start the web server and produce below output.

Web-Serve-This-Directory — Bash Screenshot

Note that since qr_encode could be detected, a QR code has been generated and can be accessed on http://192.168.1.176:8000/webserver_url.jpg.

Accessing the Web Server

The URL of the web server is displayed on the first line of the terminal output; in the above case, the URL is http://192.168.1.176:8000/. Copy-and-pasting the URL into a browser of choice or clicking the URL in the terminal, should open a page like the one below.

Web-Serve-This-Directory — Desktop Browser Directory Listing Screenshot

In case qr_encode could be detected, a QR code has been generated and placed as file webserver_url.jpg on the web server. In case no QR code is available, the URL needs to be manually entered on the mobile. Clicking on file webserver_url.jpg displays the QR code as shown below.

Web-Serve-This-Directory — Desktop Browser QR Code Screenshot

Scanning the QR code on a mobile with a suitable app opens the same page on a mobile browser as shown below.

Web-Serve-This-Directory — Android Browser Directory Listing Screenshot

Unsurprisingly, the directory listing on the mobile is identical to the directory listing displayed on the local machine. This now allows to download file Return of Sherlock Holmes (version 2 Dramatic Reading) _ Sir Arthur Conan Doyle _ English _ 1_6-WRbalzuvms4.mp3 to the mobile by tapping on the file for a longer time until the menu shown below appears.

Web-Serve-This-Directory — Android Browser Link Menu Screenshot

Selecting Download link will start the download. Depending on the size of the file and your connection speed, transferring the file can take several seconds or minutes to complete.

Stopping the Web Server

Once the file transfer has successfully completed, the web server on the local machine can be stopped by pressing Ctrl-C; this is standard Python web server behaviour.

Leveraging an Audiobook App

At this point, the audiobook version of YouTube link https://youtu.be/WRbalzuvms4 is stored on the local machine and also transferred to a mobile. The Mp3 file still needs to be used in an audiobook app that keeps track of playback positions. Even during app restarts and system reboots.

An App That Keeps Track of Playback Positions

When using the default browser settings, file Return of Sherlock Holmes (version 2 Dramatic Reading) _ Sir Arthur Conan Doyle _ English _ 1_6-WRbalzuvms4.mp3 should now be located in the default Download folder at /root/sdcard/Download which is also accessible via the Downloads app.

Common music apps should pick up the file and be able to play it back just like any other Mp3 file. However, I found these apps to be better suited for streaming or playing music as hardly any of them remember playback positions.

And especially with audiobooks, keeping track of playback positions matters. There has to be an app for that…!

Simple Audio Book Player Free

Fortunately, there is an app which is up to the job at hand. Simple Audio Book Player Free does what is says on the tin. It plays audiobooks and it’s free.

Best of all, it remembers the playback position of every audiobook. This means that it’s possible to continuously listen to multiple audiobooks even when jumping back and forth between them. Plus, I have to say that I really like the simplistic and clean design.

Simple Audiobook Player Free Screenshot

The app focuses on a single folder that can be selected by tapping the four bars icon in the middle of the second row, between the -10 and +10 seconds buttons.

When navigating the underlying folder selector dialogue to the Download folder at /root/sdcard/Download, it should pick up file Return of Sherlock Holmes (version 2 Dramatic Reading) _ Sir Arthur Conan Doyle _ English _ 1_6-WRbalzuvms4.mp3 as displayed above.

Happy listening!

Conclusion

The above end-to-end solution solves my problem of reading books at scale by carefully Sellotaping together two Bash scripts and leveraging a free audiobook player app.

While this works for me, it may be different in your case. Feel free to leave a comment or contribute to the Git repositories YouTube2Audiobook and Web-Serve-This-Directory, so we can make things better for everyone. Thanks!

Disclaimer

By using the software in this article or following any of its suggestions, you agree to always respect the copyright laws in your country and all other jurisdictions that may apply.

Moreover, you also agree to always respect the Terms of Service of the provider you are downloading content from. The author of this article or software is in no way responsible for any potential damages, liabilities, or losses.

dominic

Dominic Dumrauf

A Cloud Success Champion by profession, an avid outdoor enthusiast by heart, and a passionate barista by choice. Still hunting that elusive perfect espresso.

Read More