]>
Commit | Line | Data |
---|---|---|
1 | (ns ebooks | |
2 | (:require [clojure.java.io :as io] | |
3 | [clojure.string :refer [split]] | |
4 | [lib :refer [run-cmd extract-file-from-zip]])) | |
5 | ||
6 | ; Utilities for dealing with ebooks | |
7 | ; | |
8 | ; Dependencies: | |
9 | ; 1. calibre | |
10 | ; 2. ffmpeg | |
11 | ; 3. OS-dependent TTS software | |
12 | ||
13 | ;; TODO Check if all required utilities are installed | |
14 | ||
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." | |
18 | [book-file] | |
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))) | |
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!") | |
31 | ;; TODO Use festival-tts or say depending on OS | |
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)))) |