X-Git-Url: https://njoseph.me/gitweb/babashka-scripts.git/blobdiff_plain/ead73d37568631a52a3759179a8fde48939d4afa..57e618f2b43f69a280d1e73cb06cb470bec24e56:/ebook-to-audio-book diff --git a/ebook-to-audio-book b/ebook-to-audio-book new file mode 100755 index 0000000..ec12e96 --- /dev/null +++ b/ebook-to-audio-book @@ -0,0 +1,35 @@ +#! /usr/bin/env bb +; -*- mode: clojure -*- + +; A utility to listen to your ebooks using TTS programs + +(require '[clojure.java.io :as io] + '[clojure.string :refer [split]] + '[lib :refer [run-cmd extract-file-from-zip unixify]]) + +;; TODO Check if all required utilities are installed + +;; TODO Allow voice selection +(println "Selected voice is Samantha") + +;; TODO Use festival-tts or say depending on OS + +(defn- convert + [book-file] + (let [title (first (split book-file #"\.")) + txtz-file (str title ".txtz") + txt-file (str title ".txt") + aiff-file (str title ".aiff") + mp3-file (str title ".mp3")] + (println "Converting to text...") + (run-cmd ["ebook-convert" book-file txtz-file]) + (extract-file-from-zip txtz-file "index.txt" txt-file) + (println "Converting text to audio. Don't hold your breath!") + (run-cmd ["say" "-f" txt-file "-o" aiff-file]) + (println "Creating mp3 file...") + (run-cmd ["ffmpeg" "-i" aiff-file mp3-file]) + (println "Cleaning up...") + (run! io/delete-file [txtz-file txt-file aiff-file]) + (println (str "Done! Check out " mp3-file)))) + +(unixify convert)