Add utils and shell aliases
[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
67d5a15a
JN
5(require '[clojure.java.io :as io]
6 '[clojure.string :refer [split]]
7 '[lib :refer [run-cmd extract-file-from-zip]])
fa20f4c6
JN
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
fa20f4c6
JN
16(let [book-file (first *command-line-args*)
17 title (first (split book-file #"\."))
18 txtz-file (str title ".txtz")
19 txt-file (str title ".txt")
20 aiff-file (str title ".aiff")
21 mp3-file (str title ".mp3")]
22 (println "Converting to text...")
23 (run-cmd ["ebook-convert" book-file txtz-file])
f7a7c885 24 (extract-file-from-zip txtz-file "index.txt" txt-file)
fa20f4c6
JN
25 (println "Converting text to audio. Don't hold your breath!")
26 (run-cmd ["say" "-f" txt-file "-o" aiff-file])
27 (println "Creating mp3 file...")
28 (run-cmd ["ffmpeg" "-i" aiff-file mp3-file])
29 (println "Cleaning up...")
fbc08850 30 (run! io/delete-file [txtz-file txt-file aiff-file])
fa20f4c6 31 (println (str "Done! Check out " mp3-file)))