]> gitweb.factorcode.org Git - factor.git/commitdiff
google.translate: adding translate-tts.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 26 Apr 2013 17:42:50 +0000 (10:42 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 26 Apr 2013 17:42:50 +0000 (10:42 -0700)
extra/google/translate/translate.factor

index ed559d0c9451c3eef4e23b2c59f4e0646e1a54da..e515e749bd2d8113d2825bef72724387abdd38b7 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2010 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: assocs combinators fry grouping http.client io
-json.reader kernel locals make namespaces sequences ;
+io.encodings.binary io.files io.files.unique json.reader kernel
+locals make namespaces sequences urls ;
 IN: google.translate
 
 CONSTANT: google-translate-url "http://ajax.googleapis.com/ajax/services/language/translate"
@@ -50,6 +51,12 @@ ERROR: response-error response error ;
         swap dupd = not
     ] loop drop ;
 
+: translate-tts ( text -- file )
+    "http://translate.google.com/translate_tts?tl=en" >url
+    swap "q" set-query-param http-get nip
+    temporary-file ".mp3" append
+    [ binary set-file-contents ] keep ;
+
 ! Example:
 ! "dog" "en" "de" translate .
 ! "Hund"