voxforge.org
VoxForge Dev

Changeset 2353

Show
Ignore:
Timestamp:
11/14/07 22:40:20 (11 months ago)
Author:
kmaclean
Message:

SpeechSubmission App - more legacy code cleanup

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Trunk/SpeechSubmission/VFSpeechSubmission/java/src/speechrecorder/CapturePlayback.java

    r2352 r2353  
    194194    private File uploadWavFile9; 
    195195    private File uploadWavFile10;   
    196 //    private File archiveFile;    
    197196    private File promptsFile;   
    198197    private File readmeFile;     
    199198    private File licenseFile;    
    200199    private File licenseNoticeFile;     
    201 // !!!!!!   
    202200 
    203201//DEL    JLabel progCompletion; 
     
    209207    JTextField subjectBox; 
    210208    String subject; 
    211 //  !!!!!!  
    212209    JTextField prompt1Box;  
    213210    JTextField prompt2Box;  
     
    235232    String promptID9; 
    236233    String promptID10;   
    237 // !!!!!! 
     234// ############ Localized Fields ####################################    
    238235    JTextField usernameTextField;   
    239236    LabelLocalizer labels = new LabelLocalizer("Dutch"); 
     
    309306    String sampleGraphLengthLabel = labels.sampleGraphLengthLabel;  
    310307    String sampleGraphPositionLabel = labels.sampleGraphPositionLabel;  
    311 // !!!!!!       
    312      
    313      
     308//  ############ Localized Fields ####################################       
    314309    String fileFieldName; 
    315310     
     
    327322     
    328323        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) {            
     324public 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) {            
    338329 
    339330    if (prompt1 == null || prompt1.length() == 0) { 
     
    470461                System.err.println("CapturePlayback's WAV file for recording uploadWavFile4 is:" + uploadWavFile9); 
    471462                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)); 
    476465        EmptyBorder eb = new EmptyBorder(5,5,5,5); 
    477466        SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.LOWERED); 
    478467 
    479468        JPanel p2 = new JPanel(); 
    480         //p2.setBorder(sbb); 
    481469        p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); 
    482470//      ############ User name ####################################              
    483471//      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));      
    489477          
    490         p2.add(usernamePanel);   
     478        p2.add(usernamePanel);   
    491479// ############ Gender ####################################              
    492480        JPanel genderPanel = new JPanel(); 
     
    573561                 }); 
    574562        p2.add(dialectPanel); 
    575  
    576563//      ############ Microphone Type: ####################################        
    577564        JPanel microphonePanel = new JPanel(); 
     
    608595                 }); 
    609596        p2.add(microphonePanel); 
    610  
    611597//      ############ Prompts container ####################################    
    612598        JPanel promptsContainer = new JPanel();  
    613599        promptsContainer.setLayout(new FlowLayout(FlowLayout.CENTER)); 
    614  
    615600//      ############ Prompts panel ####################################          
    616601        JPanel prompts = new JPanel();  
     
    618603        Color voxforgeColour    = new Color(197, 216, 234); 
    619604        prompts.setBorder(BorderFactory.createLineBorder (voxforgeColour, 3)); 
    620 // ############ Prompt1 ####################################         
     605//             ############ Prompt1 ####################################         
    621606        JPanel prompt1Panel = new JPanel();  
    622607        prompt1Panel.setLayout(new FlowLayout(FlowLayout.RIGHT));  
     
    629614        capt1 = addButton(recordButton, prompt1Panel, true); 
    630615        prompts.add(prompt1Panel); 
    631 // ############ Prompt2 ####################################             
     616//             ############ Prompt2 ####################################             
    632617        JPanel prompt2Panel = new JPanel();  
    633618        prompt2Panel.setLayout(new FlowLayout(FlowLayout.RIGHT));        
     
    669654        capt5 = addButton(recordButton, prompt5Panel, false); 
    670655        prompts.add(prompt5Panel);  
    671  
    672656//      ############ Prompt6 ####################################         
    673657        JPanel prompt6Panel = new JPanel();  
     
    681665        capt6 = addButton(recordButton, prompt6Panel, false); 
    682666        prompts.add(prompt6Panel); 
    683 // ############ prompt7 ####################################             
     667//             ############ prompt7 ####################################             
    684668        JPanel prompt7Panel = new JPanel();  
    685669        prompt7Panel.setLayout(new FlowLayout(FlowLayout.RIGHT));        
     
    725709//      ############ Prompts container ####################################           
    726710        promptsContainer.add(prompts); 
    727  
    728711        p2.add(promptsContainer); 
    729712//      ############ Sampling Graph ####################################           
     
    737720        uploadTextPanel.add(new JLabel(uploadText));                
    738721        p2.add(uploadTextPanel); 
    739 //############ Upload ####################################           
     722//             ############ Upload ####################################           
    740723         JPanel uploadButtonPanel = new JPanel(); 
    741724         uploadButtonPanel.setBorder(new EmptyBorder(5,0,5,0)); 
    742725         uploadB = addButton(uploadButtonLabel, uploadButtonPanel, false); // upload all submissions 
    743726         p2.add(uploadButtonPanel); 
    744 //############ Upload Progress bar #################################### 
     727//             ############ Upload Progress bar #################################### 
    745728         progBar = new JProgressBar(); 
    746729         progBar.setStringPainted(false); 
     
    748731         //progBar.setVisible(false); 
    749732         p2.add(progBar);                
    750 // ############ More Information Button ####################################           
     733//             ############ More Information Button ####################################           
    751734         JPanel moreInfoButtonPanel = new JPanel(); 
    752735         moreInfoButtonPanel.add(new JLabel(moreInfoText)); 
    753736         moreInfoB = addButton(moreInfoButtonLabel, moreInfoButtonPanel, true);  
    754737         p2.add(moreInfoButtonPanel);    
    755 // ############ Disclaimer ####################################   
     738//             ############ Disclaimer ####################################   
    756739         JPanel DisclaimerPanel = new JPanel(); 
    757740         DisclaimerPanel.setLayout(new FlowLayout(FlowLayout.CENTER));  
     
    760743         aboutB = addButton(aboutButtonLabel, DisclaimerInnerPanel, true);  
    761744         DisclaimerInnerPanel.setBorder(BorderFactory.createLineBorder (voxforgeColour, 3)); 
    762   
    763745         DisclaimerPanel.add(DisclaimerInnerPanel);         
    764         p2.add(DisclaimerPanel);  
     746        p2.add(DisclaimerPanel);  
    765747//#########################################################################    
    766748        add(p2); 
     
    787769    public void close() { 
    788770        if (playback.thread != null) { 
    789     //        playB.doClick(0); 
    790771            play1.doClick(0); 
    791772            play2.doClick(0); 
     
    813794        } 
    814795    } 
    815  
    816796 
    817797    private JButton addButton(String name, JPanel p, boolean state) { 
     
    10691049            fileName = promptID1; 
    10701050            samplingGraph.start(); 
    1071             // !!!!!! 
    10721051            saveButtonState();  
    10731052            setButtonsOff();  
    10741053            capt1.setEnabled(true);     
    1075             // play1.setEnabled(false); 
    1076             // !!!!!! 
    10771054            capt1.setText(stopButton); 
    10781055            moreInfoB.setEnabled(false);   
     
    10821059            capture.stop(); 
    10831060            samplingGraph.stop(); 
    1084             restoreButtonState(); //!!!!!! 
     1061            restoreButtonState();  
    10851062            play1.setEnabled(true); 
    10861063            capt1.setText(recordButton); 
     
    10991076              fileName = promptID2; 
    11001077              samplingGraph.start(); 
    1101               // !!!!!! 
    11021078              saveButtonState();  
    11031079              setButtonsOff();  
    11041080              capt2.setEnabled(true);     
    1105               // play2.setEnabled(false); 
    1106               // !!!!!! 
    11071081              capt2.setText(stopButton); 
    11081082              moreInfoB.setEnabled(false); 
     
    11121086              capture.stop(); 
    11131087              samplingGraph.stop(); 
    1114               restoreButtonState(); //!!!!!! 
     1088              restoreButtonState();  
    11151089              play2.setEnabled(true); 
    11161090              capt2.setText(recordButton); 
     
    11291103              fileName = promptID3; 
    11301104              samplingGraph.start(); 
    1131               // !!!!!! 
    11321105              saveButtonState();  
    11331106              setButtonsOff();  
    11341107              capt3.setEnabled(true);     
    1135               // play3.setEnabled(false); 
    1136               // !!!!!! 
    11371108              capt3.setText(stopButton); 
    11381109              moreInfoB.setEnabled(false); 
     
    11421113              capture.stop(); 
    11431114              samplingGraph.stop(); 
    1144               restoreButtonState(); //!!!!!! 
     1115              restoreButtonState();  
    11451116              play3.setEnabled(true); 
    11461117              capt3.setText(recordButton); 
     
    11601131              fileName = promptID4; 
    11611132              samplingGraph.start(); 
    1162               // !!!!!! 
    11631133              saveButtonState();  
    11641134              setButtonsOff();  
    11651135              capt4.setEnabled(true);     
    1166               // play4.setEnabled(false); 
    1167               // !!!!!! 
    11681136              capt4.setText(stopButton); 
    11691137              moreInfoB.setEnabled(false);   
     
    11731141              capture.stop(); 
    11741142              samplingGraph.stop(); 
    1175               restoreButtonState(); //!!!!!! 
     1143              restoreButtonState();  
    11761144              play4.setEnabled(true); 
    11771145              capt4.setText(recordButton); 
     
    11791147              aboutB.setEnabled(true);  
    11801148              capt5.setEnabled(true); 
    1181  
    11821149          } 
    11831150        }  
     
    11911158              fileName = promptID5; 
    11921159              samplingGraph.start(); 
    1193               // !!!!!! 
    11941160              saveButtonState();  
    11951161              setButtonsOff();  
    11961162              capt5.setEnabled(true);     
    1197               // play5.setEnabled(false); 
    1198               // !!!!!! 
    11991163              capt5.setText(stopButton); 
    12001164              moreInfoB.setEnabled(false); 
     
    12041168              capture.stop(); 
    12051169              samplingGraph.stop(); 
    1206               restoreButtonState(); //!!!!!! 
     1170              restoreButtonState();  
    12071171              play5.setEnabled(true); 
    12081172              capt5.setText(recordButton); 
     
    12101174              aboutB.setEnabled(true);  
    12111175              capt6.setEnabled(true); 
    1212  
    12131176          } 
    12141177        }     
     
    12221185              fileName = promptID6; 
    12231186              samplingGraph.start(); 
    1224               // !!!!!! 
    12251187              saveButtonState();  
    12261188              setButtonsOff();  
    12271189              capt6.setEnabled(true);     
    1228               // play6.setEnabled(false); 
    1229               // !!!!!! 
    12301190              capt6.setText(stopButton); 
    12311191              moreInfoB.setEnabled(false);   
     
    12351195              capture.stop(); 
    12361196              samplingGraph.stop(); 
    1237               restoreButtonState(); //!!!!!! 
     1197              restoreButtonState();  
    12381198              play6.setEnabled(true); 
    12391199              capt6.setText(recordButton); 
     
    12521212                fileName = promptID7; 
    12531213                samplingGraph.start(); 
    1254                 // !!!!!! 
    12551214                saveButtonState();  
    12561215                setButtonsOff();  
    12571216                capt7.setEnabled(true);     
    1258                 // play7.setEnabled(false); 
    1259                 // !!!!!! 
    12601217                capt7.setText(stopButton); 
    12611218                moreInfoB.setEnabled(false);   
     
    12651222                capture.stop(); 
    12661223                samplingGraph.stop(); 
    1267                 restoreButtonState(); //!!!!!! 
     1224                restoreButtonState();  
    12681225                play7.setEnabled(true); 
    12691226                capt7.setText(recordButton); 
     
    12821239                fileName = promptID8; 
    12831240                samplingGraph.start(); 
    1284                 // !!!!!! 
    12851241                saveButtonState();  
    12861242                setButtonsOff();  
    12871243                capt8.setEnabled(true);     
    1288                 // play8.setEnabled(false); 
    1289                 // !!!!!! 
    12901244                capt8.setText(stopButton); 
    12911245                moreInfoB.setEnabled(false);   
     
    12951249                capture.stop(); 
    12961250                samplingGraph.stop(); 
    1297                 restoreButtonState(); //!!!!!! 
     1251                restoreButtonState();  
    12981252                play8.setEnabled(true); 
    12991253                capt8.setText(recordButton); 
     
    13121266                fileName = promptID9; 
    13131267                samplingGraph.start(); 
    1314                 // !!!!!! 
    13151268                saveButtonState();  
    13161269                setButtonsOff();  
    13171270                capt9.setEnabled(true);     
    1318                 // play9.setEnabled(false); 
    1319                 // !!!!!! 
    13201271                capt9.setText(stopButton); 
    13211272                moreInfoB.setEnabled(false);  
     
    13251276                capture.stop(); 
    13261277                samplingGraph.stop(); 
    1327                 restoreButtonState(); //!!!!!! 
     1278                restoreButtonState();  
    13281279                play9.setEnabled(true); 
    13291280                capt9.setText(recordButton); 
     
    13421293                fileName = promptID10; 
    13431294                samplingGraph.start(); 
    1344                 // !!!!!! 
    13451295                saveButtonState();  
    13461296                setButtonsOff();  
    13471297                capt10.setEnabled(true);     
    1348                 // play10.setEnabled(false); 
    1349                 // !!!!!! 
    13501298                capt10.setText(stopButton); 
    13511299                moreInfoB.setEnabled(false);   
     
    13551303                capture.stop(); 
    13561304                samplingGraph.stop(); 
    1357                 restoreButtonState(); //!!!!!! 
     1305                restoreButtonState();  
    13581306                play10.setEnabled(true); 
    13591307                capt10.setText(recordButton); 
     
    13901338                   usernameTextField.selectAll(); 
    13911339                   userName = usernameTextField.getText(); 
    1392                    //!!!!!! 
    13931340                   // see   java.util.regex.Pattern 
    13941341                   //      \w   A word character: [a-zA-Z_0-9] 
    13951342                   //      \W   A non-word character: [^\w] 
    13961343                           userName = (usernameTextField.getText().replaceAll("\\W","")); 
    1397                    // !!!!!! 
    13981344                   if (userName.length() == 0 ) { 
    13991345                       userName = "anonymous"; 
    14001346                   } else { 
    1401                            // !!!!!!       
    14021347                                   if (userName.length() > 25 ) { 
    14031348                                           userName = userName.substring(0,25); 
    14041349                           }  
    1405                                    // !!!!!! 
    14061350                   } 
    1407                     
    14081351                } catch (NullPointerException ex) {  
    14091352               userName = "anonymous"; 
     
    15481491                thread = null; 
    15491492                samplingGraph.stop(); 
    1550 // !!!!!!        FIXME          
    15511493              if (play1.getText().startsWith(stopButton)) { //play button gets set to "Stop" after play is pressed 
    15521494                  capt1.setEnabled(true);  
     
    15701512                  capt10.setEnabled(true);  
    15711513              } 
    1572                
    15731514              play1.setText(playButton); 
    15741515              play2.setText(playButton); 
     
    15811522              play9.setText(playButton); 
    15821523              play10.setText(playButton);  
    1583 //            !!!!!!                
    15841524            }  
    15851525        } 
     
    16441584            // start the source data line 
    16451585            line.start(); 
    1646                 // !!!!!! 
    16471586            ByteArrayOutputStream outbaos = new ByteArrayOutputStream(); 
    16481587            while (thread != null) { 
     
    16671606            progBar.setString(samplingGraph.peakWarning ?  
    16681607                        peakWarningLabel : ""); 
    1669             // !!!!!! 
    16701608            while (thread != null) { 
    16711609                try { 
     
    16911629            line = null; 
    16921630            System.err.println("reached end of file"); 
    1693             // !!!!!! 
    1694  
    1695             // !!!!!! 
    16961631 
    16971632            shutDown(null); 
     
    17211656  
    17221657        public void start(File uploadWavFile) { 
    1723                 this.uploadWavFile = uploadWavFile; // !!!!!! 
     1658                this.uploadWavFile = uploadWavFile;  
    17241659                System.err.println("Capture uploadWavFile is:" + uploadWavFile); 
    17251660 
     
    17801715                return; 
    17811716            } 
    1782             // !!!!!! 
    1783                 //ByteArrayOutputStream out = new ByteArrayOutputStream(); 
    1784                 ByteArrayOutputStream outbaos = new ByteArrayOutputStream(); 
    1785             // !!!!!! 
     1717            ByteArrayOutputStream outbaos = new ByteArrayOutputStream(); 
    17861718            System.err.println("TargetDataLine allocated has this AudioFormat: " + line.getFormat()); 
    17871719 
     
    18131745                                        totalBytesWritten += numBytesRead; 
    18141746                                        out.write(data, 0, numBytesRead); 
    1815                                         // !!!!!! 
    18161747                                        outbaos.write(data, 0, numBytesRead); 
    1817                                         // !!!!!! 
    18181748                                } 
    18191749                        } catch(IOException err){ 
     
    18471777                } 
    18481778            } 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"); 
    18511780                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"); 
    18641784            samplingGraph.createWaveForm(audioBytes); 
    1865 // !!!!!! 
    18661785            // debug System.err.println("Created samplingGraph"); 
    1867  
    18681786            // This is the only way to "reset" long streams - re-grab 
    1869            
    18701787            getAudioInputStream(); 
    18711788 
     
    19611878            encoder.dtx = true; 
    19621879 
    1963  
    1964 /* DEL - WE USE THE FILE RATHER THAN THE STREAM NOW 
    1965  
    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 file 
    1968  
    1969             // make sure we have something to play 
    1970             if (audioInputStream == null) { 
    1971                 shutDown("No loaded audio to convert/upload"); 
    1972                 return; 
    1973             } 
    1974             // reset to the beginning of the stream 
    1975             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 playback 
    1987             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  
    19981880            try { 
    19991881//DEL WHEN NEW METHOD                if (AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, wavFile) == -1) { 
     
    20291911//  System.err.println("Adding subject to URL"); 
    20301912  try { 
    2031 // !!!!!! 
    2032 //        destinationURL = new URL(destinationURL.toString() + "&subject=" 
    2033 //         + java.net.URLEncoder.encode(subjectBox.getText(), "UTF-8")); 
    20341913          destinationURL = new URL(destinationURL.toString());     
    2035 // !!!!!!          
    20361914  }catch(Exception err){ 
    20371915    System.err.println(err); 
     
    20411919 
    20421920File[] 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 */ 
    20541921//############ audio files ####################################  
    20551922files[1] = uploadWavFile1; 
     
    20781945    out_prompts.write(promptID10 + " " + prompt10 + System.getProperty("line.separator"));       
    20791946    out_prompts.close(); 
    2080        } catch (IOException e) { 
     1947} catch (IOException e) { 
    20811948            System.err.println("Problems with prompts"); 
    2082        }  
     1949}  
    20831950files[11] = promptsFile; 
    20841951//############ ReadMe file####################################