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