]> njoseph.me Git - babashka-scripts.git/blame - ebook-to-audio-book.clj
git-pull-all & ebook-to-audio-book
[babashka-scripts.git] / ebook-to-audio-book.clj
CommitLineData
fa20f4c6
JN
1#! /usr/bin/env bb
2
3; A utility to listen to your ebooks using TTS programs
4
5(require '[babashka.process :as p]
6 '[clojure.java.io :as io]
7 '[clojure.string :refer [split]])
8
9;; TODO Check if all required utilities are installed
10
11;; TODO Allow voice selection
12(println "Selected voice is Samantha")
13
14;; TODO Use festival-tts or say depending on OS
15
16(defn run-cmd
17 [command]
18 (->> command
19 p/process
20 :out
21 slurp))
22
23(let [book-file (first *command-line-args*)
24 title (first (split book-file #"\."))
25 txtz-file (str title ".txtz")
26 txt-file (str title ".txt")
27 aiff-file (str title ".aiff")
28 mp3-file (str title ".mp3")]
29 (println "Converting to text...")
30 (run-cmd ["ebook-convert" book-file txtz-file])
31 (spit txt-file (run-cmd ["unzip" "-p" txtz-file "index.txt"]))
32 (println "Converting text to audio. Don't hold your breath!")
33 (run-cmd ["say" "-f" txt-file "-o" aiff-file])
34 (println "Creating mp3 file...")
35 (run-cmd ["ffmpeg" "-i" aiff-file mp3-file])
36 (println "Cleaning up...")
37 (doseq [temp-file [txtz-file txt-file aiff-file]]
38 (io/delete-file temp-file))
39 (println (str "Done! Check out " mp3-file)))