| 1 |
package speechrecorder; |
|---|
| 2 |
|
|---|
| 3 |
import java.util.Random; |
|---|
| 4 |
import java.util.StringTokenizer; |
|---|
| 5 |
import java.io.*; |
|---|
| 6 |
|
|---|
| 7 |
class Prompts { |
|---|
| 8 |
private String [] promptList; |
|---|
| 9 |
private String [] englishPromptList = { |
|---|
| 10 |
"rp-01 When the sunlight strikes raindrops in the air,", |
|---|
| 11 |
"rp-02 they act as a prism and form a rainbow.", |
|---|
| 12 |
"rp-03 The rainbow is a division of white light into many beautiful colors.", |
|---|
| 13 |
"rp-04 These take the shape of a long round arch, with its path high above,", |
|---|
| 14 |
"rp-05 and its two ends apparently beyond the horizon.", |
|---|
| 15 |
"rp-06 There is , according to legend, a boiling pot of gold at one end.", |
|---|
| 16 |
"rp-07 People look, but no one ever finds it.", |
|---|
| 17 |
"rp-08 When a man looks for something beyond his reach,", |
|---|
| 18 |
"rp-09 his friends say he is looking for the pot of gold at the end of the rainbow.", |
|---|
| 19 |
"rp-10 Throughout the centuries people have explained the rainbow in various ways.", |
|---|
| 20 |
"rp-11 Some have accepted it as a miracle without physical explanation.", |
|---|
| 21 |
"rp-12 To the Hebrews it was a token that there would be no more universal floods.", |
|---|
| 22 |
"rp-13 The Greeks used to imagine that it was a sign", |
|---|
| 23 |
"rp-14 from the gods to foretell war or heavy rain.", |
|---|
| 24 |
"rp-15 The Norsemen considered the rainbow as a bridge", |
|---|
| 25 |
"rp-16 over which the gods passed from earth to their home in the sky.", |
|---|
| 26 |
"rp-17 Others have tried to explain the phenomenon physically.", |
|---|
| 27 |
"rp-18 Aristotle thought that the rainbow was caused by", |
|---|
| 28 |
"rp-19 reflection of the sun's rays by the rain.", |
|---|
| 29 |
"rp-20 Since then physicists have found that it is not reflection,", |
|---|
| 30 |
"rp-21 but refraction by the raindrops which causes the rainbows.", |
|---|
| 31 |
"rp-22 Many complicated ideas about the rainbow have been formed.", |
|---|
| 32 |
"rp-23 The difference in the rainbow depends considerably upon the size of the drops,", |
|---|
| 33 |
"rp-24 and the width of the colored band increases as the size of the drops increases.", |
|---|
| 34 |
"rp-25 The actual primary rainbow observed is said to be the effect of", |
|---|
| 35 |
"rp-26 super-imposition of a number of bows.", |
|---|
| 36 |
"rp-27 If the red of the second bow falls upon the green of the first,", |
|---|
| 37 |
"rp-28 the result is to give a bow with an abnormally wide yellow band,", |
|---|
| 38 |
"rp-29 since red and green light when mixed form yellow.", |
|---|
| 39 |
"rp-30 This is a very common type of bow, one showing mainly red and yellow,", |
|---|
| 40 |
"rp-31 with little or no green or blue." , |
|---|
| 41 |
"ar-01 Once there was a young rat named Arthur who never could make up his mind.", |
|---|
| 42 |
"ar-02 Whenever his friends asked him if he would like to go out with them,", |
|---|
| 43 |
"ar-03 he would only answer, \"I don't know;\" he wouldn't say yes or no either.", |
|---|
| 44 |
"ar-04 He would always shirk making a choice. His Aunt Helen said to him,", |
|---|
| 45 |
"ar-05 \"Now look here! No one is going to care for you if you carry on like this.\"", |
|---|
| 46 |
"ar-06 You have no more mind than a blade of grass.", |
|---|
| 47 |
"ar-07 One rainy day the rats heard a great noise in the loft.", |
|---|
| 48 |
"ar-08 The pine rafters were all rotten, so that the barn was rather unsafe.", |
|---|
| 49 |
"ar-09 At last the joists gave way and fell to the ground.", |
|---|
| 50 |
"ar-10 The walls shook, and all the rats' hair stood on end with fear and horror.", |
|---|
| 51 |
"ar-11 \"This won't do,\" said the captain; \"I'll send out scouts to search for a new home.\"", |
|---|
| 52 |
"ar-12 Within five hours the ten scouts came back and said,", |
|---|
| 53 |
"ar-13 We found a stone house where there is room for us all.", |
|---|
| 54 |
"ar-14 There is a kindly horse named Nelly, a cow, a calf, and a garden with an elm tree.", |
|---|
| 55 |
"ar-15 The rats crawled out of their little houses and stood on the floor in a long line.", |
|---|
| 56 |
"ar-16 Just then the old rat saw Arthur. Stop. he ordered coarsely.", |
|---|
| 57 |
"ar-17 \"You are coming, of course.\" \"I'm not certain,\" said Arthur, undaunted,", |
|---|
| 58 |
"ar-18 \"The roof may not come down yet.\"", |
|---|
| 59 |
"ar-19 \"Well,\" said the old rat, \"we can't wait for you to join us. Right about face! March!\"", |
|---|
| 60 |
"ar-20 Arthur stood and watched them hurry away.", |
|---|
| 61 |
"ar-21 \"I think I'll go tomorrow,\" he said calmly to himself, \"but then again I don't know;\"", |
|---|
| 62 |
"ar-22 \"it's so nice and snug here,\". That night there was a big crash.", |
|---|
| 63 |
"ar-23 In the foggy morning some men with some boys and girls rode up and looked at the barn.", |
|---|
| 64 |
"ar-24 One of them moved a board and saw a rat quite dead, half in and half out of his hole.", |
|---|
| 65 |
}; |
|---|
| 66 |
|
|---|
| 67 |
private String [][] promptSubset; |
|---|
| 68 |
|
|---|
| 69 |
public Prompts(int NumberofPrompts, String Language) { |
|---|
| 70 |
if (Language.equals("EN")) { |
|---|
| 71 |
promptList = getPromptTextFile("englishPromptList.txt", 1223); |
|---|
| 72 |
} else if (Language.equals("NL")) { |
|---|
| 73 |
promptList = getPromptTextFile("nl","dutchPromptList.txt", 947); |
|---|
| 74 |
} else if (Language.equals("DE")) { |
|---|
| 75 |
promptList = getPromptTextFile("germanPromptList.txt", 1211); |
|---|
| 76 |
} else if (Language.equals("RU")) { |
|---|
| 77 |
promptList = getPromptTextFile("russianPromptList.txt", 81); |
|---|
| 78 |
} else if (Language.equals("IT")) { |
|---|
| 79 |
promptList = getPromptTextFile("it","italianPromptList.txt", 1185); |
|---|
| 80 |
} else if (Language.equals("HB")) { |
|---|
| 81 |
promptList = getPromptTextFile("hebrewPromptList.txt", 55); |
|---|
| 82 |
} else if (Language.equals("PT_BR")) { |
|---|
| 83 |
promptList = getPromptTextFile("brazilianPromptList.txt", 218); |
|---|
| 84 |
} else if (Language.equals("ES")) { |
|---|
| 85 |
promptList = getPromptTextFile("es","spanishPromptList.txt", 43); |
|---|
| 86 |
} else if (Language.equals("FR")) { |
|---|
| 87 |
promptList = getPromptTextFile("frenchPromptList.txt", 865); |
|---|
| 88 |
} else { |
|---|
| 89 |
System.err.println("getPromptTextFile error accessing prompt file for "+ Language + "using default English prompts"); |
|---|
| 90 |
promptList = englishPromptList; |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
promptSubset = new String [2][NumberofPrompts]; |
|---|
| 94 |
|
|---|
| 95 |
Random randomGenerator = new Random(); |
|---|
| 96 |
int arrayLength = promptList.length - 1; |
|---|
| 97 |
int nextPrompt = randomGenerator.nextInt(arrayLength); |
|---|
| 98 |
for (int idx=0;idx<NumberofPrompts; idx++) { |
|---|
| 99 |
if (nextPrompt <= arrayLength) { |
|---|
| 100 |
getPromptLine(nextPrompt, idx); |
|---|
| 101 |
} else { |
|---|
| 102 |
nextPrompt = 0; |
|---|
| 103 |
getPromptLine(nextPrompt, idx); |
|---|
| 104 |
} |
|---|
| 105 |
nextPrompt++; |
|---|
| 106 |
} |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
public String [][] getPrompts() { |
|---|
| 110 |
return promptSubset; |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
private void getPromptLine(int nextPrompt, int idx) { |
|---|
| 114 |
String promptID; |
|---|
| 115 |
StringBuffer prompt = new StringBuffer(); |
|---|
| 116 |
|
|---|
| 117 |
StringTokenizer st = new StringTokenizer(promptList[nextPrompt]); |
|---|
| 118 |
String [] words= new String [st.countTokens()]; |
|---|
| 119 |
int i = 0; |
|---|
| 120 |
while (st.hasMoreTokens()) { |
|---|
| 121 |
words[i] = st.nextToken(); i++; |
|---|
| 122 |
} |
|---|
| 123 |
promptID = words[0]; |
|---|
| 124 |
|
|---|
| 125 |
int j = 0; |
|---|
| 126 |
if (words.length > 0) { |
|---|
| 127 |
for (i=1; i<words.length; i++,j++) { |
|---|
| 128 |
prompt.append(words[i]); |
|---|
| 129 |
prompt.append(" "); |
|---|
| 130 |
} |
|---|
| 131 |
} |
|---|
| 132 |
promptSubset [0][idx] = promptID; |
|---|
| 133 |
promptSubset [1][idx] = prompt.toString(); |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
private String [] getPromptTextFile(String File, int numberOfPrompts) { |
|---|
| 137 |
String [] words= new String [numberOfPrompts]; |
|---|
| 138 |
try { |
|---|
| 139 |
InputStream is = getClass().getResourceAsStream(File); |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
InputStreamReader isr = new InputStreamReader(is,"UTF-8" ); |
|---|
| 143 |
System.err.println(System.getProperty("line.separator") + "PromptList Character Encoding:" + isr.getEncoding()); |
|---|
| 144 |
|
|---|
| 145 |
BufferedReader br = new BufferedReader(isr); |
|---|
| 146 |
String line; |
|---|
| 147 |
int i = 0; |
|---|
| 148 |
while ((line = br.readLine()) != null) { |
|---|
| 149 |
words[i] = line; |
|---|
| 150 |
i++; |
|---|
| 151 |
} |
|---|
| 152 |
} catch (IOException io) { |
|---|
| 153 |
System.err.println("getPromptTextFile error accessing text file for "+File + "using default prompts"); |
|---|
| 154 |
return englishPromptList; |
|---|
| 155 |
} |
|---|
| 156 |
return words; |
|---|
| 157 |
} |
|---|
| 158 |
|
|---|
| 159 |
private String [] getPromptTextFile(String Prefix, String File, int numberOfPrompts) { |
|---|
| 160 |
String [] words= new String [numberOfPrompts]; |
|---|
| 161 |
try { |
|---|
| 162 |
InputStream is = getClass().getResourceAsStream(File); |
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
InputStreamReader isr = new InputStreamReader(is,"UTF-8" ); |
|---|
| 166 |
System.err.println(System.getProperty("line.separator") + "PromptList Character Encoding:" + isr.getEncoding()); |
|---|
| 167 |
|
|---|
| 168 |
BufferedReader br = new BufferedReader(isr); |
|---|
| 169 |
String line; |
|---|
| 170 |
int i = 0; |
|---|
| 171 |
while ((line = br.readLine()) != null) { |
|---|
| 172 |
|
|---|
| 173 |
words[i] = Prefix + "-" + paddedZeros(i,4) + " " + line; |
|---|
| 174 |
i++; |
|---|
| 175 |
} |
|---|
| 176 |
} catch (IOException io) { |
|---|
| 177 |
System.err.println("getPromptTextFile error accessing text file for "+File + "using default prompts"); |
|---|
| 178 |
return englishPromptList; |
|---|
| 179 |
} |
|---|
| 180 |
return words; |
|---|
| 181 |
} |
|---|
| 182 |
|
|---|
| 183 |
public String paddedZeros(int number, int numLength) |
|---|
| 184 |
{ |
|---|
| 185 |
String s = Integer.toString(number); |
|---|
| 186 |
if (s.length() > numLength) { |
|---|
| 187 |
return s.substring(0,numLength); |
|---|
| 188 |
} else if (s.length() < numLength) { |
|---|
| 189 |
return "0000000000".substring(0, numLength - s.length ()) + s; |
|---|
| 190 |
} else { |
|---|
| 191 |
return s; |
|---|
| 192 |
} |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
} |
|---|