]> njoseph.me Git - babashka-scripts.git/blame - ebook-to-audio-book
git-pull-all: Fix failure on non-git directories
[babashka-scripts.git] / ebook-to-audio-book
CommitLineData
fa20f4c6 1#! /usr/bin/env bb
57e618f2 2; -*- mode: clojure -*-
fa20f4c6
JN
3
4; A utility to listen to your ebooks using TTS programs
5
67d5a15a
JN
6(require '[clojure.java.io :as io]
7 '[clojure.string :refer [split]]
76cc62f0 8 '[lib :refer [run-cmd extract-file-from-zip unixify]])
fa20f4c6
JN
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
76cc62f0
JN
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)