-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Play audio directly from HTTP response; update dependencies
Since we're already fetching it into memory as a byte array, there's no need to write it to disk first
- Loading branch information
Showing
2 changed files
with
8 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
(defproject facts/speech-synthesis "1.0.0" | ||
(defproject facts/speech-synthesis "1.0.1" | ||
:description "A library to speak text." | ||
:dependencies [[org.clojure/clojure "1.3.0"] | ||
[clj-http "0.2.5"] | ||
[fs "1.0.0"] | ||
:dependencies [[org.clojure/clojure "1.5.1"] | ||
[clj-http "1.0.1"] | ||
[de.huxhorn.sulky/de.huxhorn.sulky.3rdparty.jlayer "1.0"]] | ||
:dev-dependencies [[swank-clojure "1.4.0-SNAPSHOT"] | ||
[lein-clojars "0.6.0"]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,13 @@ | ||
(ns speech-synthesis.say | ||
(:require [clj-http.client :as client] | ||
[fs.core :as fs] | ||
[clojure.java.io :as io]) | ||
(:import (java.io File FileOutputStream) | ||
(:require [clj-http.client :as client]) | ||
(:import (java.io File FileOutputStream ByteArrayInputStream) | ||
(javazoom.jl.player Player))) | ||
|
||
(defn say [response] | ||
(let [mp3 (:body (client/get "http://translate.google.com/translate_tts" | ||
{:query-params {"ie" "UTF-8" | ||
"tl" "en" | ||
"q" response} | ||
:as :byte-array})) | ||
file (fs/temp-file "say" ".mp3")] | ||
(with-open [file (FileOutputStream. file)] | ||
(.write file mp3)) | ||
(with-open [player (new Player (io/input-stream file))] | ||
(.play player)))) | ||
:as :byte-array})) ] | ||
(with-open [player (new Player (ByteArrayInputStream. mp3))] | ||
(.play player)))) |