Changeset 2353
- Timestamp:
- 11/14/07 22:40:20 (11 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
Trunk/SpeechSubmission/VFSpeechSubmission/java/src/speechrecorder/CapturePlayback.java
r2352 r2353 194 194 private File uploadWavFile9; 195 195 private File uploadWavFile10; 196 // private File archiveFile;197 196 private File promptsFile; 198 197 private File readmeFile; 199 198 private File licenseFile; 200 199 private File licenseNoticeFile; 201 // !!!!!!202 200 203 201 //DEL JLabel progCompletion; … … 209 207 JTextField subjectBox; 210 208 String subject; 211 // !!!!!!212 209 JTextField prompt1Box; 213 210 JTextField prompt2Box; … … 235 232 String promptID9; 236 233 String promptID10; 237 // !!!!!!234 // ############ Localized Fields #################################### 238 235 JTextField usernameTextField; 239 236 LabelLocalizer labels = new LabelLocalizer("Dutch"); … … 309 306 String sampleGraphLengthLabel = labels.sampleGraphLengthLabel; 310 307 String sampleGraphPositionLabel = labels.sampleGraphPositionLabel; 311 // !!!!!! 312 313 308 // ############ Localized Fields #################################### 314 309 String fileFieldName; 315 310 … … 327 322 328 323 String tempdir = getTempDir(); 329 // !!!!!! 330 // public CapturePlayback(String subject, String fileFieldName, 331 // String language, URL destinationURL, 332 // URL endPageURL, URL helpPageURL, String cookie, int defaultCompressionMode) { 333 public CapturePlayback(String subject, 334 String promptID1, String prompt1, String promptID2, String prompt2, String promptID3, String prompt3, String promptID4, String prompt4, String promptID5, String prompt5, 335 String promptID6, String prompt6, String promptID7, String prompt7, String promptID8, String prompt8, String promptID9, String prompt9, String promptID10, String prompt10, 336 String fileFieldName,String language, URL destinationURL, 337 URL endPageURL, URL helpPageURL, String cookie, int defaultCompressionMode) { 324 public CapturePlayback(String subject, 325 String promptID1, String prompt1, String promptID2, String prompt2, String promptID3, String prompt3, String promptID4, String prompt4, String promptID5, String prompt5, 326 String promptID6, String prompt6, String promptID7, String prompt7, String promptID8, String prompt8, String promptID9, String prompt9, String promptID10, String prompt10, 327 String fileFieldName,String language, URL destinationURL, 328 URL endPageURL, URL helpPageURL, String cookie, int defaultCompressionMode) { 338 329 339 330 if (prompt1 == null || prompt1.length() == 0) { … … 470 461 System.err.println("CapturePlayback's WAV file for recording uploadWavFile4 is:" + uploadWavFile9); 471 462 System.err.println("CapturePlayback's WAV file for recording uploadWavFile5 is:" + uploadWavFile10); 472 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 473 //setLayout(new GridBagLayout()); 474 //GridBagConstraints gbc = new GridBagConstraints(); // Will be re-used for each item 475 463 464 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 476 465 EmptyBorder eb = new EmptyBorder(5,5,5,5); 477 466 SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.LOWERED); 478 467 479 468 JPanel p2 = new JPanel(); 480 //p2.setBorder(sbb);481 469 p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); 482 470 // ############ User name #################################### 483 471 // userName is read when user clicks Upload 484 JPanel usernamePanel = new JPanel();485 usernamePanel.setLayout(new FlowLayout(FlowLayout.CENTER));486 usernamePanel.add(new JLabel(usernamePanelLabel));487 usernamePanel.add(usernameTextField = new JTextField(20));488 usernamePanel.add(new JLabel(usernamePanelText));472 JPanel usernamePanel = new JPanel(); 473 usernamePanel.setLayout(new FlowLayout(FlowLayout.CENTER)); 474 usernamePanel.add(new JLabel(usernamePanelLabel)); 475 usernamePanel.add(usernameTextField = new JTextField(20)); 476 usernamePanel.add(new JLabel(usernamePanelText)); 489 477 490 p2.add(usernamePanel);478 p2.add(usernamePanel); 491 479 // ############ Gender #################################### 492 480 JPanel genderPanel = new JPanel(); … … 573 561 }); 574 562 p2.add(dialectPanel); 575 576 563 // ############ Microphone Type: #################################### 577 564 JPanel microphonePanel = new JPanel(); … … 608 595 }); 609 596 p2.add(microphonePanel); 610 611 597 // ############ Prompts container #################################### 612 598 JPanel promptsContainer = new JPanel(); 613 599 promptsContainer.setLayout(new FlowLayout(FlowLayout.CENTER)); 614 615 600 // ############ Prompts panel #################################### 616 601 JPanel prompts = new JPanel(); … … 618 603 Color voxforgeColour = new Color(197, 216, 234); 619 604 prompts.setBorder(BorderFactory.createLineBorder (voxforgeColour, 3)); 620 // ############ Prompt1 ####################################605 // ############ Prompt1 #################################### 621 606 JPanel prompt1Panel = new JPanel(); 622 607 prompt1Panel.setLayout(new FlowLayout(FlowLayout.RIGHT)); … … 629 614 capt1 = addButton(recordButton, prompt1Panel, true); 630 615 prompts.add(prompt1Panel); 631 // ############ Prompt2 ####################################616 // ############ Prompt2 #################################### 632 617 JPanel prompt2Panel = new JPanel(); 633 618 prompt2Panel.setLayout(new FlowLayout(FlowLayout.RIGHT)); … … 669 654 capt5 = addButton(recordButton, prompt5Panel, false); 670 655 prompts.add(prompt5Panel); 671 672 656 // ############ Prompt6 #################################### 673 657 JPanel prompt6Panel = new JPanel(); … … 681 665 capt6 = addButton(recordButton, prompt6Panel, false); 682 666 prompts.add(prompt6Panel); 683 // ############ prompt7 ####################################667 // ############ prompt7 #################################### 684 668 JPanel prompt7Panel = new JPanel(); 685 669 prompt7Panel.setLayout(new FlowLayout(FlowLayout.RIGHT)); … … 725 709 // ############ Prompts container #################################### 726 710 promptsContainer.add(prompts); 727 728 711 p2.add(promptsContainer); 729 712 // ############ Sampling Graph #################################### … … 737 720 uploadTextPanel.add(new JLabel(uploadText)); 738 721 p2.add(uploadTextPanel); 739 // ############ Upload ####################################722 // ############ Upload #################################### 740 723 JPanel uploadButtonPanel = new JPanel(); 741 724 uploadButtonPanel.setBorder(new EmptyBorder(5,0,5,0)); 742 725 uploadB = addButton(uploadButtonLabel, uploadButtonPanel, false); // upload all submissions 743 726 p2.add(uploadButtonPanel); 744 // ############ Upload Progress bar ####################################727 // ############ Upload Progress bar #################################### 745 728 progBar = new JProgressBar(); 746 729 progBar.setStringPainted(false); … … 748 731 //progBar.setVisible(false); 749 732 p2.add(progBar); 750 // ############ More Information Button ####################################733 // ############ More Information Button #################################### 751 734 JPanel moreInfoButtonPanel = new JPanel(); 752 735 moreInfoButtonPanel.add(new JLabel(moreInfoText)); 753 736 moreInfoB = addButton(moreInfoButtonLabel, moreInfoButtonPanel, true); 754 737 p2.add(moreInfoButtonPanel); 755 // ############ Disclaimer ####################################738 // ############ Disclaimer #################################### 756 739 JPanel DisclaimerPanel = new JPanel(); 757 740 DisclaimerPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); … … 760 743 aboutB = addButton(aboutButtonLabel, DisclaimerInnerPanel, true); 761 744 DisclaimerInnerPanel.setBorder(BorderFactory.createLineBorder (voxforgeColour, 3)); 762 763 745 DisclaimerPanel.add(DisclaimerInnerPanel); 764 p2.add(DisclaimerPanel);746 p2.add(DisclaimerPanel); 765 747 //######################################################################### 766 748 add(p2); … … 787 769 public void close() { 788 770 if (playback.thread != null) { 789 // playB.doClick(0);790 771 play1.doClick(0); 791 772 play2.doClick(0); … … 813 794 } 814 795 } 815 816 796 817 797 private JButton addButton(String name, JPanel p, boolean state) { … … 1069 1049 fileName = promptID1; 1070 1050 samplingGraph.start(); 1071 // !!!!!!1072 1051 saveButtonState(); 1073 1052 setButtonsOff(); 1074 1053 capt1.setEnabled(true); 1075 // play1.setEnabled(false);1076 // !!!!!!1077 1054 capt1.setText(stopButton); 1078 1055 moreInfoB.setEnabled(false); … … 1082 1059 capture.stop(); 1083 1060 samplingGraph.stop(); 1084 restoreButtonState(); //!!!!!!1061 restoreButtonState(); 1085 1062 play1.setEnabled(true); 1086 1063 capt1.setText(recordButton); … … 1099 1076 fileName = promptID2; 1100 1077 samplingGraph.start(); 1101 // !!!!!!1102 1078 saveButtonState(); 1103 1079 setButtonsOff(); 1104 1080 capt2.setEnabled(true); 1105 // play2.setEnabled(false);1106 // !!!!!!1107 1081 capt2.setText(stopButton); 1108 1082 moreInfoB.setEnabled(false); … … 1112 1086 capture.stop(); 1113 1087 samplingGraph.stop(); 1114 restoreButtonState(); //!!!!!!1088 restoreButtonState(); 1115 1089 play2.setEnabled(true); 1116 1090 capt2.setText(recordButton); … … 1129 1103 fileName = promptID3; 1130 1104 samplingGraph.start(); 1131 // !!!!!!1132 1105 saveButtonState(); 1133 1106 setButtonsOff(); 1134 1107 capt3.setEnabled(true); 1135 // play3.setEnabled(false);1136 // !!!!!!1137 1108 capt3.setText(stopButton); 1138 1109 moreInfoB.setEnabled(false); … … 1142 1113 capture.stop(); 1143 1114 samplingGraph.stop(); 1144 restoreButtonState(); //!!!!!!1115 restoreButtonState(); 1145 1116 play3.setEnabled(true); 1146 1117 capt3.setText(recordButton); … … 1160 1131 fileName = promptID4; 1161 1132 samplingGraph.start(); 1162 // !!!!!!1163 1133 saveButtonState(); 1164 1134 setButtonsOff(); 1165 1135 capt4.setEnabled(true); 1166 // play4.setEnabled(false);1167 // !!!!!!1168 1136 capt4.setText(stopButton); 1169 1137 moreInfoB.setEnabled(false); … … 1173 1141 capture.stop(); 1174 1142 samplingGraph.stop(); 1175 restoreButtonState(); //!!!!!!1143 restoreButtonState(); 1176 1144 play4.setEnabled(true); 1177 1145 capt4.setText(recordButton); … … 1179 1147 aboutB.setEnabled(true); 1180 1148 capt5.setEnabled(true); 1181 1182 1149 } 1183 1150 } … … 1191 1158 fileName = promptID5; 1192 1159 samplingGraph.start(); 1193 // !!!!!!1194 1160 saveButtonState(); 1195 1161 setButtonsOff(); 1196 1162 capt5.setEnabled(true); 1197 // play5.setEnabled(false);1198 // !!!!!!1199 1163 capt5.setText(stopButton); 1200 1164 moreInfoB.setEnabled(false); … … 1204 1168 capture.stop(); 1205 1169 samplingGraph.stop(); 1206 restoreButtonState(); //!!!!!!1170 restoreButtonState(); 1207 1171 play5.setEnabled(true); 1208 1172 capt5.setText(recordButton); … … 1210 1174 aboutB.setEnabled(true); 1211 1175 capt6.setEnabled(true); 1212 1213 1176 } 1214 1177 } … … 1222 1185 fileName = promptID6; 1223 1186 samplingGraph.start(); 1224 // !!!!!!1225 1187 saveButtonState(); 1226 1188 setButtonsOff(); 1227 1189 capt6.setEnabled(true); 1228 // play6.setEnabled(false);1229 // !!!!!!1230 1190 capt6.setText(stopButton); 1231 1191 moreInfoB.setEnabled(false); … … 1235 1195 capture.stop(); 1236 1196 samplingGraph.stop(); 1237 restoreButtonState(); //!!!!!!1197 restoreButtonState(); 1238 1198 play6.setEnabled(true); 1239 1199 capt6.setText(recordButton); … … 1252 1212 fileName = promptID7; 1253 1213 samplingGraph.start(); 1254 // !!!!!!1255 1214 saveButtonState(); 1256 1215 setButtonsOff(); 1257 1216 capt7.setEnabled(true); 1258 // play7.setEnabled(false);1259 // !!!!!!1260 1217 capt7.setText(stopButton); 1261 1218 moreInfoB.setEnabled(false); … … 1265 1222 capture.stop(); 1266 1223 samplingGraph.stop(); 1267 restoreButtonState(); //!!!!!!1224 restoreButtonState(); 1268 1225 play7.setEnabled(true); 1269 1226 capt7.setText(recordButton); … … 1282 1239 fileName = promptID8; 1283 1240 samplingGraph.start(); 1284 // !!!!!!1285 1241 saveButtonState(); 1286 1242 setButtonsOff(); 1287 1243 capt8.setEnabled(true); 1288 // play8.setEnabled(false);1289 // !!!!!!1290 1244 capt8.setText(stopButton); 1291 1245 moreInfoB.setEnabled(false); … … 1295 1249 capture.stop(); 1296 1250 samplingGraph.stop(); 1297 restoreButtonState(); //!!!!!!1251 restoreButtonState(); 1298 1252 play8.setEnabled(true); 1299 1253 capt8.setText(recordButton); … … 1312 1266 fileName = promptID9; 1313 1267 samplingGraph.start(); 1314 // !!!!!!1315 1268 saveButtonState(); 1316 1269 setButtonsOff(); 1317 1270 capt9.setEnabled(true); 1318 // play9.setEnabled(false);1319 // !!!!!!1320 1271 capt9.setText(stopButton); 1321 1272 moreInfoB.setEnabled(false); … … 1325 1276 capture.stop(); 1326 1277 samplingGraph.stop(); 1327 restoreButtonState(); //!!!!!!1278 restoreButtonState(); 1328 1279 play9.setEnabled(true); 1329 1280 capt9.setText(recordButton); … … 1342 1293 fileName = promptID10; 1343 1294 samplingGraph.start(); 1344 // !!!!!!1345 1295 saveButtonState(); 1346 1296 setButtonsOff(); 1347 1297 capt10.setEnabled(true); 1348 // play10.setEnabled(false);1349 // !!!!!!1350 1298 capt10.setText(stopButton); 1351 1299 moreInfoB.setEnabled(false); … … 1355 1303 capture.stop(); 1356 1304 samplingGraph.stop(); 1357 restoreButtonState(); //!!!!!!1305 restoreButtonState(); 1358 1306 play10.setEnabled(true); 1359 1307 capt10.setText(recordButton); … … 1390 1338 usernameTextField.selectAll(); 1391 1339 userName = usernameTextField.getText(); 1392 //!!!!!!1393 1340 // see java.util.regex.Pattern 1394 1341 // \w A word character: [a-zA-Z_0-9] 1395 1342 // \W A non-word character: [^\w] 1396 1343 userName = (usernameTextField.getText().replaceAll("\\W","")); 1397 // !!!!!!1398 1344 if (userName.length() == 0 ) { 1399 1345 userName = "anonymous"; 1400 1346 } else { 1401 // !!!!!!1402 1347 if (userName.length() > 25 ) { 1403 1348 userName = userName.substring(0,25); 1404 1349 } 1405 // !!!!!!1406 1350 } 1407 1408 1351 } catch (NullPointerException ex) { 1409 1352 userName = "anonymous"; … … 1548 1491 thread = null; 1549 1492 samplingGraph.stop(); 1550 // !!!!!! FIXME1551 1493 if (play1.getText().startsWith(stopButton)) { //play button gets set to "Stop" after play is pressed 1552 1494 capt1.setEnabled(true); … … 1570 1512 capt10.setEnabled(true); 1571 1513 } 1572 1573 1514 play1.setText(playButton); 1574 1515 play2.setText(playButton); … … 1581 1522 play9.setText(playButton); 1582 1523 play10.setText(playButton); 1583 // !!!!!!1584 1524 } 1585 1525 } … … 1644 1584 // start the source data line 1645 1585 line.start(); 1646 // !!!!!!1647 1586 ByteArrayOutputStream outbaos = new ByteArrayOutputStream(); 1648 1587 while (thread != null) { … … 1667 1606 progBar.setString(samplingGraph.peakWarning ? 1668 1607 peakWarningLabel : ""); 1669 // !!!!!!1670 1608 while (thread != null) { 1671 1609 try { … … 1691 1629 line = null; 1692 1630 System.err.println("reached end of file"); 1693 // !!!!!!1694 1695 // !!!!!!1696 1631 1697 1632 shutDown(null); … … 1721 1656 1722 1657 public void start(File uploadWavFile) { 1723 this.uploadWavFile = uploadWavFile; // !!!!!!1658 this.uploadWavFile = uploadWavFile; 1724 1659 System.err.println("Capture uploadWavFile is:" + uploadWavFile); 1725 1660 … … 1780 1715 return; 1781 1716 } 1782 // !!!!!! 1783 //ByteArrayOutputStream out = new ByteArrayOutputStream(); 1784 ByteArrayOutputStream outbaos = new ByteArrayOutputStream(); 1785 // !!!!!! 1717 ByteArrayOutputStream outbaos = new ByteArrayOutputStream(); 1786 1718 System.err.println("TargetDataLine allocated has this AudioFormat: " + line.getFormat()); 1787 1719 … … 1813 1745 totalBytesWritten += numBytesRead; 1814 1746 out.write(data, 0, numBytesRead); 1815 // !!!!!!1816 1747 outbaos.write(data, 0, numBytesRead); 1817 // !!!!!!1818 1748 } 1819 1749 } catch(IOException err){ … … 1847 1777 } 1848 1778 } catch (Exception ex) { reportStatus(ex.toString()); } 1849 // !!!!!! 1850 // debug System.err.println("About to load bytes to byte array"); 1779 // debug System.err.println("About to load bytes to byte array"); 1851 1780 byte audioBytes[] = outbaos.toByteArray(); 1852 // System.err.println("Loaded bytes to byte array"); 1853 // ByteArrayInputStream bais = new ByteArrayInputStream(audioBytes); 1854 // audioInputStream = new AudioInputStream(bais, format, audioBytes.length / frameSizeInBytes); 1855 // System.err.println("Grabbed audio stream"); 1856 // long milliseconds = (long)((audioInputStream.getFrameLength() * 1000) / format.getFrameRate()); 1857 // duration = milliseconds / 1000.0; 1858 1859 duration = totalBytesWritten / (double) (format.getSampleRate() * format.getSampleSizeInBits()/ 8); 1860 // !!!!!! 1861 // debug System.err.println("Calculated duration"); 1862 // !!!!!! 1863 // samplingGraph.createWaveForm(audioInputStream); 1781 1782 duration = totalBytesWritten / (double) (format.getSampleRate() * format.getSampleSizeInBits()/ 8); 1783 // debug System.err.println("Calculated duration"); 1864 1784 samplingGraph.createWaveForm(audioBytes); 1865 // !!!!!!1866 1785 // debug System.err.println("Created samplingGraph"); 1867 1868 1786 // This is the only way to "reset" long streams - re-grab 1869 1870 1787 getAudioInputStream(); 1871 1788 … … 1961 1878 encoder.dtx = true; 1962 1879 1963 1964 /* DEL - WE USE THE FILE RATHER THAN THE STREAM NOW1965 1966 // audioInputStream should be a stream containing the audio buffer content.1967 // We test that it's OK and then we write it to a temp file1968 1969 // make sure we have something to play1970 if (audioInputStream == null) {1971 shutDown("No loaded audio to convert/upload");1972 return;1973 }1974 // reset to the beginning of the stream1975 try {1976 audioInputStream.reset();1977 } catch (Exception e) {1978 shutDown("Unable to reset the stream\n" + e);1979 return;1980 }1981 */1982 1983 1984 1985 /* DEL??? WHAT IS THIS BIT??1986 // get an AudioInputStream of the desired format for playback1987 AudioInputStream playbackInputStream = AudioSystem.getAudioInputStream(format, audioInputStream);1988 1989 if (playbackInputStream == null) {1990 shutDown("Unable to convert stream of format "1991 + audioInputStream + " to format " + format);1992 return;1993 }1994 1995 System.err.println("playbackInputStream.getFormat(): " + playbackInputStream.getFormat());1996 */1997 1998 1880 try { 1999 1881 //DEL WHEN NEW METHOD if (AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, wavFile) == -1) { … … 2029 1911 // System.err.println("Adding subject to URL"); 2030 1912 try { 2031 // !!!!!!2032 // destinationURL = new URL(destinationURL.toString() + "&subject="2033 // + java.net.URLEncoder.encode(subjectBox.getText(), "UTF-8"));2034 1913 destinationURL = new URL(destinationURL.toString()); 2035 // !!!!!!2036 1914 }catch(Exception err){ 2037 1915 System.err.println(err); … … 2041 1919 2042 1920 File[] files = new File[15]; 2043 // !!!!!!2044 // files[0] = spxFile;2045 //trying to convert from pcm to wav files (i.e. add a wav header to the pcm file)2046 /*2047 try {2048 AudioInputStream uploadInputStream = AudioSystem.getAudioInputStream(wavFile1);2049 AudioSystem.write(uploadInputStream, AudioFileFormat.Type.WAVE, wavFile1);2050 }catch(UnsupportedAudioFileException err){2051 System.err.println(err);2052 }2053 */2054 1921 //############ audio files #################################### 2055 1922 files[1] = uploadWavFile1; … … 2078 1945 out_prompts.write(promptID10 + " " + prompt10 + System.getProperty("line.separator")); 2079 1946 out_prompts.close(); 2080 } catch (IOException e) {1947 } catch (IOException e) { 2081 1948 System.err.println("Problems with prompts"); 2082 }1949 } 2083 1950 files[11] = promptsFile; 2084 1951 //############ ReadMe file####################################