Esempio n. 1
0
 /**
  * Stop recording and give us the clip.
  *
  * @return the clip that was recorded since the last time start was called
  * @see #start
  */
 public short[] stop() {
   synchronized (lock) {
     if (recorder == null) {
       return new short[0];
     }
     ByteArrayOutputStream out = recorder.stopRecording();
     microphone.close();
     recorder = null;
     byte audioBytes[] = out.toByteArray();
     ByteArrayInputStream in = new ByteArrayInputStream(audioBytes);
     try {
       short[] samples = RawReader.readAudioData(in, inFormat);
       if (downsample) {
         samples =
             Downsampler.downsample(
                 samples,
                 (int) (inFormat.getSampleRate() / 1000.0f),
                 (int) (outFormat.getSampleRate() / 1000.0f));
       }
       return samples;
     } catch (IOException e) {
       e.printStackTrace();
       return new short[0];
     }
   }
 }
Esempio n. 2
0
 /**
  * Start recording. The stop method will give us the clip.
  *
  * @see #stop
  */
 public void start() {
   synchronized (lock) {
     if (recorder != null) {
       recorder.stopRecording();
     }
     recorder = new RecordThread();
     recorder.start();
   }
 }