]> njoseph.me Git - babashka-scripts.git/blame - scripts/ebooks.clj
Add .lsp/ folder to .gitignore
[babashka-scripts.git] / scripts / ebooks.clj
CommitLineData
ec37ad05
JN
1(ns ebooks
2 (:require [clojure.java.io :as io]
3 [clojure.string :refer [split]]
4 [lib :refer [run-cmd extract-file-from-zip]]))
fa20f4c6 5
ec37ad05 6; Utilities for dealing with ebooks
746d6404 7;
ec37ad05
JN
8; Dependencies:
9; 1. calibre
10; 2. ffmpeg
11; 3. OS-dependent TTS software
fa20f4c6
JN
12
13;; TODO Check if all required utilities are installed
fa20f4c6 14
ec37ad05
JN
15;; TODO Use tools.cli to provide more options
16(defn convert-ebook-to-audiobook
17 "A utility to listen to your ebooks using TTS programs. This utility only works on macOS for now."
76cc62f0 18 [book-file]
ec37ad05
JN
19 ;; TODO Allow voice selection
20 (let [default-voice (run-cmd ["defaults" "read" "com.apple.speech.voice.prefs" "SelectedVoiceName"])]
21 (println (str "Will read using the default voice " default-voice)))
76cc62f0
JN
22 (let [title (first (split book-file #"\."))
23 txtz-file (str title ".txtz")
24 txt-file (str title ".txt")
25 aiff-file (str title ".aiff")
26 mp3-file (str title ".mp3")]
27 (println "Converting to text...")
28 (run-cmd ["ebook-convert" book-file txtz-file])
29 (extract-file-from-zip txtz-file "index.txt" txt-file)
30 (println "Converting text to audio. Don't hold your breath!")
ec37ad05 31 ;; TODO Use festival-tts or say depending on OS
76cc62f0
JN
32 (run-cmd ["say" "-f" txt-file "-o" aiff-file])
33 (println "Creating mp3 file...")
34 (run-cmd ["ffmpeg" "-i" aiff-file mp3-file])
35 (println "Cleaning up...")
36 (run! io/delete-file [txtz-file txt-file aiff-file])
37 (println (str "Done! Check out " mp3-file))))