1 19 package org.lucane.applications.audioconf.audio; 20 21 import java.io.*; 22 23 26 public class FileOutput implements AudioRecorderListener 27 { 28 private String filename; 30 private FileOutputStream output; 31 32 37 public FileOutput(String filename) 38 { 39 this.filename = filename; 40 } 41 42 45 public void audioRecordingStarted(AudioConfig config) 46 { 47 try { 48 this.output = new FileOutputStream(this.filename); 49 System.out.println("recording 10 seconds..."); 50 } catch (FileNotFoundException e) { 51 e.printStackTrace(); 52 } 53 } 54 55 58 public void audioRecorded(byte[] data, int length) 59 { 60 try { 61 System.out.println("recorded : " +length); 62 this.output.write(data, 0, length); 63 } catch (IOException e) { 64 e.printStackTrace(); 65 } 66 } 67 68 71 public void audioRecordingEnded() 72 { 73 try { 74 this.output.close(); 75 System.out.println("ended."); 76 } catch (IOException e) { 77 e.printStackTrace(); 78 } 79 } 80 81 84 public static void main(String [] args) 85 throws Exception 86 { 87 AudioConfig config = new AudioConfig(AudioConfig.NARROWBAND, 3); 88 FileOutput fo = new FileOutput("test.spx"); 89 AudioRecorder ar = new AudioRecorder(config); 90 ar.addAudioListener(fo); 91 92 Thread t = new Thread (ar); 93 94 t.start(); 95 Thread.sleep(10*1000); 96 ar.stop(); 97 98 System.out.println(t.isAlive()); 99 } 100 } | Popular Tags |