]> njoseph.me Git - babashka-scripts.git/blame_incremental - ebook-to-audio-book
ebook-to-audio-book: Get the correct default voice
[babashka-scripts.git] / ebook-to-audio-book
... / ...
CommitLineData
1#! /usr/bin/env bb
2; -*- mode: clojure -*-
3
4; A utility to listen to your ebooks using TTS programs
5;
6; This utility only works on macOS for now.
7
8(require '[clojure.java.io :as io]
9 '[clojure.string :refer [split]]
10 '[lib :refer [run-cmd extract-file-from-zip unixify]])
11
12;; TODO Check if all required utilities are installed
13;; TODO Allow voice selection
14
15(let [default-voice (run-cmd ["defaults" "read" "com.apple.speech.voice.prefs" "SelectedVoiceName"])]
16 (println (str "Will read using the default voice " default-voice)))
17
18;; TODO Use festival-tts or say depending on OS
19
20(defn- convert
21 [book-file]
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 (run-cmd ["say" "-f" txt-file "-o" aiff-file])
32 (println "Creating mp3 file...")
33 (run-cmd ["ffmpeg" "-i" aiff-file mp3-file])
34 (println "Cleaning up...")
35 (run! io/delete-file [txtz-file txt-file aiff-file])
36 (println (str "Done! Check out " mp3-file))))
37
38(unixify convert)