Skip to content

Instantly share code, notes, and snippets.

@psibre
Forked from seblemaguer/example mary 6.gradle
Last active April 13, 2017 16:15
Show Gist options
  • Save psibre/05eaa6b584ed970177bd04e2a3d66f5f to your computer and use it in GitHub Desktop.
Save psibre/05eaa6b584ed970177bd04e2a3d66f5f to your computer and use it in GitHub Desktop.
dependencies {
classpath group: "org.codehaus.groovy.modules.http-builder", name: "http-builder", version: "0.7"
}
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.URLENC
import static groovyx.net.http.Method.POST
import static groovyx.net.http.ContentType.JSON
def configuration = """
# How to extract the input
input_serializer=marytts.io.TextSerializer
# How to render the output
output_serializer=marytts.io.XMLSerializer
# Current locale
locale=en_GB
# List of modules
modules=marytts.language.en.Preprocess \
marytts.language.en.JTokenizer \
marytts.modules.nlp.OpenNLPPosTagger \
marytts.modules.nlp.JPhonemiser
"""
def http = new HTTPBuilder('http://falken-3:59126/')
def result = http.request(POST, JSON) { req ->
uri.path = '/process'
requestContentType = URLENC
body = [input: input_file.text, configuration:configuration] // will be url-encoded
response.success = { resp ->
String text = resp.entity.content.text
String contentType = resp.headers."Content-Type"
if (contentType?.startsWith("application/json")) {
def json = slurper.parseText(text)
if (json.exception)
{
print(json.exception)
}
else
{
output_file.text = json.result
}
}
else {
// FIXME: error
}
}
response.failure = { resp ->
println "Unexpected error: ${resp.status} : ${resp.statusLine.reasonPhrase}"
resp.headers.each { println "${it.name} : ${it.value}" }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment