-
Notifications
You must be signed in to change notification settings - Fork 0
/
Synthesize.java
66 lines (52 loc) · 2.12 KB
/
Synthesize.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package marytts;
// Java base
import java.io.FileInputStream;
import java.io.File;
import java.io.PrintWriter;
import java.nio.file.*;
// Logger
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
// Mary configuration
import marytts.config.MaryConfiguration;
import marytts.config.JSONMaryConfigLoader;
// Runtime / Request
import marytts.runutils.Mary;
import marytts.runutils.Request;
/**
* Class example to call marytts
*
* @author <a href="mailto:lemagues@tcd.ie">Sébastien Le Maguer</a>
*/
public class Synthesize
{
protected static Logger logger = LogManager.getLogger(Synthesize.class.toString());
public static void main(String[] args) throws Exception {
File input_dir = new File(args[0]);
File output_dir = new File(args[1]);
File config_file = new File(args[2]);
// Starting up mary (should be global but I put it here for example purpose)
Mary.startup();
// Read configuration
MaryConfiguration configuration = (new JSONMaryConfigLoader()).loadConfiguration(new FileInputStream(config_file));
// Do something
for (final File text_file : input_dir.listFiles()) {
// Get the content text
String input_text = new String(Files.readAllBytes(text_file.toPath()));
// Achieve the request
logger.info("=================================================================================");
Request request = new Request(configuration, input_text);
request.process();
String output = request.serializeFinaleUtterance().toString();
logger.info("=================================================================================\n");
// Dump the output
output_dir.mkdirs();
File output_file = new File(output_dir, text_file.getName() + ".xml");
PrintWriter writer = new PrintWriter(output_file);
writer.println(output);
writer.close();
}
// Shutting down mary (should be global but I put it here for example purpose)
Mary.shutdown();
}
}