Skip to content

Instantly share code, notes, and snippets.

@seblemaguer
Last active June 26, 2017 06:53
Show Gist options
  • Save seblemaguer/b52ee84c844e8d548ebcef1ae9a3d6c6 to your computer and use it in GitHub Desktop.
Save seblemaguer/b52ee84c844e8d548ebcef1ae9a3d6c6 to your computer and use it in GitHub Desktop.
MaryTTS 6.0.X calling from gradle
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
task computeDescriptiveFeatures() {
def input_file = new File("$text_path/${filename}.txt")
def output_file = new File("$buildDir/${filename}.desc")
def configuration_file = new File("mary_configuration.properties")
inputs.files input_file, configuration_file
outputs.files output_file
doLast {
def configuration = configuration_file.text
def http = new HTTPBuilder('http://falken-3:59126/')
http.request( POST, JSON ) {
uri.path = '/process'
uri.query = [input: input_file.text, configuration:configuration] // will be url-encoded
response.success = { resp, json ->
output_file.text = json["result"]
}
}
}
}
# How to extract the input
input_serializer=marytts.io.serializer.TextSerializer
# How to render the output
output_serializer=marytts.io.serializer.MaryTextGridSerializer
# Current locale
locale=en_US
# List of modules
modules=marytts.language.en.Preprocess \
marytts.language.en.JTokenizer \
marytts.modules.nlp.OpenNLPPosTagger \
marytts.modules.nlp.JPhonemiser
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
# HTTP + URL packages
import json, requests
# To play wave files
import pygame
import math # For ceiling
# Mary server informations
mary_host = "falken-3"
mary_port = "59126"
# Input text
input = None
with open(sys.argv[2]) as f:
input = f.read()
# Configuration
configuration = None
with open(sys.argv[1]) as f_conf:
configuration = f_conf.read()
# Build the query
query = {"input":input,"configuration":configuration}
# Run the query to mary http server
headers = {"Content-type": "application/x-www-form-urlencoded"} # FIXME: mandatory but why ?
r = requests.post("http://%s:%s/process/" % (mary_host, mary_port),
headers = headers,
data = query)
map = r.json()
if map["exception"]:
exception = map["exception"]
if "embeddedException" in exception:
exception = map["exception"]["embeddedException"]
if "embeddedException" in exception:
exception = map["exception"]["embeddedException"]
print(exception)
for l in exception["stackTrace"]:
print("%s:%d %s.%s " % (l["fileName"], l["lineNumber"], l["className"], l["methodName"]))
for t in l:
if t not in ["fileName", "lineNumber", "className", "methodName", "nativeMethod"]:
print("\t%s - %s" % (t, l[t]))
else:
print(map["result"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment