-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFestival.java
102 lines (82 loc) · 2.46 KB
/
Festival.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package beta;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.SwingWorker;
public class Festival extends SwingWorker<Void, Integer>{
private String _tts;
private String _voice;
private JButton _btn;
//Getting the values to be used.
public Festival(String tts,String voice) throws Exception{
this(tts, voice, null);
}
//Getting the values to be used.
public Festival(String tts,String voice, JButton btn) throws Exception{
_tts=tts;
_voice = voice;
_btn = btn;
}
//When it is executed, festival is played.
@Override
protected Void doInBackground() throws Exception {
setScheme(_tts, _voice);
festival();
return null;
}
private void festival() throws Exception{
//command to be excuted.
String cmd = "festival -b festival.scm";
ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", cmd);
//Excute the command
Process process = builder.start();
//Wait for the previous process to be finihsed
process.waitFor();
}
public void done() {
if (_btn != null) {
_btn.setEnabled(true);
}
}
private void setScheme(String tts, String voice) throws IOException{
File failed = new File("festival.scm");
//If file does not exist, create new file
if(!failed.exists()) {
failed.createNewFile();
}
//Appending the word to the file
Writer output;
output = new BufferedWriter(new FileWriter(failed,false));
output.append("(voice_"+_voice+")\n");
output.append("(Parameter.set 'Duration_Stretch 1.2)");
String[] lines = tts.split("!!");
for(int i =0; i<lines.length;i++){
output.append("(SayText \""+lines[i]+"\")");
}
output.close();
}
//Get the list of available voice on the current machine.
public ArrayList<String> listOfVoices() throws Exception{
ArrayList<String> voice = new ArrayList<String>();
String cmd = "ls /usr/share/festival/voices/*english* > ./.voices";
ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", cmd);
//Excute the command
Process process = builder.start();
//Wait for the previous process to be finihsed
process.waitFor();
BufferedReader file = new BufferedReader(new FileReader("."+File.separator+".voices"));
String line;
while ((line = file.readLine()) != null){
if(!"".equals(line.trim())){
voice.add(line);
}
}
return voice;
}
}