]> njoseph.me Git - babashka-scripts.git/blob - ebook-to-audio-book.clj
Integrate clj-kondo. Add .gitignore
[babashka-scripts.git] / ebook-to-audio-book.clj
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 (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])
24 (extract-file-from-zip txtz-file "index.txt" txt-file)
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...")
30 (run! io/delete-file [txtz-file txt-file aiff-file])
31 (println (str "Done! Check out " mp3-file)))