]> njoseph.me Git - babashka-scripts.git/blame - ebook-to-audio-book
ebook-to-audio-book: Get the correct default voice
[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
746d6404
JN
5;
6; This utility only works on macOS for now.
fa20f4c6 7
67d5a15a
JN
8(require '[clojure.java.io :as io]
9 '[clojure.string :refer [split]]
76cc62f0 10 '[lib :refer [run-cmd extract-file-from-zip unixify]])
fa20f4c6
JN
11
12;; TODO Check if all required utilities are installed
fa20f4c6 13;; TODO Allow voice selection
746d6404
JN
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)))
fa20f4c6
JN
17
18;; TODO Use festival-tts or say depending on OS
19
76cc62f0
JN
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)