How can I compress an audio sample?

Hi, I have raw audio sample in a byte array. I want to compress this sample. more specifically, I want to develop a method which will take this byte array as an input and returns the compressed sample in the byte array again. Please suggest me if anyone knows about this.
The code which I am using for capturing the data through the microphone is as follows. After executing the following, a byteArrayOutputStream is created, from which I am getting the captured audio byte array just by calling byteArrayOutputStream.toByteArray() method.
public void captureAudio(){
    try{
      //Get everything set up for
      // capture
      audioFormat = getAudioFormat();
      DataLine.Info dataLineInfo =
                new DataLine.Info(
                  TargetDataLine.class,
                   audioFormat);
      targetDataLine = (TargetDataLine)
                   AudioSystem.getLine(
                         dataLineInfo);
      targetDataLine.open(audioFormat);
      targetDataLine.start();
      //Create a thread to capture the
      // microphone data and start it
      // running.  It will run until
      // the Stop button is clicked.
      Thread captureThread =
                new Thread(
                  new CaptureThread());
      captureThread.start();
    } catch (Exception e) {
      System.out.println(e);
      System.exit(0);
    }//end catch
  }//end captureAudio method
class CaptureThread extends Thread{
  //An arbitrary-size temporary holding
  // buffer
  byte tempBuffer[] = new byte[10000];
  public void run(){
    byteArrayOutputStream =
           new ByteArrayOutputStream();
    stopCapture = false;
    try{//Loop until stopCapture is set
        // by another thread that
        // services the Stop button.
      while(!stopCapture){
        //Read data from the internal
        // buffer of the data line.
        int cnt = targetDataLine.read(
                    tempBuffer,
                    0,
                    tempBuffer.length);
        if(cnt > 0){
          //Save data in output stream
          // object.
          byteArrayOutputStream.write(
                   tempBuffer, 0, cnt);
        }//end if
      }//end while
      byteArrayOutputStream.close();
    }catch (Exception e) {
      System.out.println(e);
      System.exit(0);
    }//end catch
  }//end run
}//end inner class CaptureThreadI am new to sound api and I hope you got my question. Please ask me if anything required from my side.
Regards

Thanks Andrew and Captfoss, I agree both of you and I am really a newbie. Andrew, you are talking about the decreasing the quality, like what we do in video conferencing application where quality of an image not really matters [we set the jpeg quality to 0.5 etc]. I'll definitely do that. Please tell me the values for lower quality sound. The audio format I am using currently is as follows:
private AudioFormat getAudioFormat(){
    float sampleRate = 8000.0F;
    //8000,11025,16000,22050,44100
    int sampleSizeInBits = 16;
    //8,16
    int channels = 1;
    //1,2
    boolean signed = true;
    //true,false
    boolean bigEndian = false;
    //true,false
    return new AudioFormat(
                      sampleRate,
                      sampleSizeInBits,
                      channels,
                      signed,
                      bigEndian);
  }//end getAudioFormatcaptfoss, I also thought of ULAW compression. But I am not getting the way to apply this compression on the piece of sound which is stored in a byte[]. I am capturing the sound in piece by piece through the microphone.each piece of sound is stored in a byte[]. Now I want to compress this byte[] using ULAW. How can I do that? I don't have any file on the hard disk as I am capturing through the mic. Also, I don't want the compressed file to be stored on the hard disk. Instead, I'll want the compressed output in a byte[].

Similar Messages

  • How can I create an audio CD from the audio only portion of my iMovie?

    Hello, I brought in about 50 min of Digital video into iMovie, I separated (split) the audio from the video, I unlocked the audio, I deleted the video, and now I want to just create an audio CD from the audio that is left.
    Can I do this? and if yes how? If I can not, how can I create an Audio CD from on my G5 off a tape on my digital camcorder?
    Any help would be apprecaited.

    This is how:
    Go to:
    'File'
    'Share'
    'Quicktime'
    'Expert Settings'
    'Audio as AIFF' or pick your brand of compression.
    Drag and drop the resulting file into iTunes.
    Enjoy!
    P.S. - You didn't need to delete the video but I think that'll be okay.

  • HT201441 how can i create and audio cd from a music track I have on my ipod

    how can i create and audio cd from a music track I have on my ipod

    This is how:
    Go to:
    'File'
    'Share'
    'Quicktime'
    'Expert Settings'
    'Audio as AIFF' or pick your brand of compression.
    Drag and drop the resulting file into iTunes.
    Enjoy!
    P.S. - You didn't need to delete the video but I think that'll be okay.

  • How Can I select an Audio Hardware with AudioQueue ?

    Hello,
    Apple is providing this Demo Code...
    http://developer.apple.com/samplecode/AudioQueueTest/AudioQueueTest.dmg
    but how can I select the Audio Hardware? I want to write an application that should output to 4 different USB Audio Cards. Is that possible?
    I am searching for hours now
    Thanks,
    Klaus

    I confirm your issue as I just tried an audio CD in my XP laptop. "All Files" showed only the 44 byte .cda files and no others. QuickTime couldn't open them (error -2048).
    I also tried "Open File" with version 7 Pro and it couldn't open.
    Odd that I get the option to open using iTunes and it opens and plays just fine. Since iTunes uses the QuickTime engine I would have thought QuickTime could read the files directly.
    The same audio CD inserted in my Mac allowed me to double click any track and it opened directly in QuickTime Player. The files show as .aiff files measured in MB's.
    Windows users could open an audio CD in iTunes and then convert to .aiff (no compression) and then open the .aiff in QuickTime.
    I guess I should have tried myself before getting your hopes up. I apologize.

  • How can I play an audio CD with QT 7.1.6?

    I want to play an audio CD with QuickTime 7.1.6.
    When I click on Open file and select the CD drive, change th file type to Audio Files and mark "Open as read-only" nothing is displayed. When I change to "All Files (.)" the tracks are showed with an ".cda" extension. When I dobleclick on a track, I get the Error -2048: the file is not a movie file.
    How can I play an audio CD with QuickTime 7.1.6?

    I confirm your issue as I just tried an audio CD in my XP laptop. "All Files" showed only the 44 byte .cda files and no others. QuickTime couldn't open them (error -2048).
    I also tried "Open File" with version 7 Pro and it couldn't open.
    Odd that I get the option to open using iTunes and it opens and plays just fine. Since iTunes uses the QuickTime engine I would have thought QuickTime could read the files directly.
    The same audio CD inserted in my Mac allowed me to double click any track and it opened directly in QuickTime Player. The files show as .aiff files measured in MB's.
    Windows users could open an audio CD in iTunes and then convert to .aiff (no compression) and then open the .aiff in QuickTime.
    I guess I should have tried myself before getting your hopes up. I apologize.

  • How can I convert an AUDIO MPEG-4 to an MPEG3 format? I need it for a Powerpoint Presentation

    How can I convert an AUDIO  MPEG-4 to another type of file, such as MPEG3  or mp3

    Use Handbrake.
    You can download it for free from this site:
    http://www.macupdate.com/info.php/id/12987/handbrake
    Good luck

  • How can I copy an audio effect from a clip and paste it to another clip in the same timiline...With FCPro 7 it was all so fast........

    how can I copy an audio effect from a clip and paste it to another clip in the same timiline...With FCPro 7 it was all so fast........

    Tom Wolsky wrote:
    The advantage goes to FCP7 if you allow that it can copy and paste filters, audio and video, transformations, and other attributes separately.
    You can do that in FCPX too, as all the things you cited are listed separately in the inspector.
    Here's a little gotcha. Let's say you've color corrected a few clips and you've applied an effect to one and want to paste it the other clips. You switch off color correction and copy the clip. You select the other clips and paste effects. What do you think happens? The effect is applied, but the color correction is applied as well, only it's switched off as it was in the first clip, so all the color correction on the other clips is lost. Fun, eh?
    I'll try to replicate your gotcha - but no, that doesn't sound like fun at all!

  • I recorded an interview on my iPad using the iTalk app. How can I transfer that audio to my MacBook Pro? The file is too big to email.

    I recorded an interview on my iPad using the iTalk app. How can I transfer that audio to my MacBook Pro? The file is too big to email.

    Use DropBox. https://www.dropbox.com/help/84/en
     Cheers, Tom

  • How can I record an audio sound and convert it to a ringtone?

    How can I record an audio sound and convert it to a ringtone?

    Record your voice using iPhone (for ringtone only 35 secs or under are valid), sync iPhone with iTunes.
    In iTunes the recorded voice is listed under Music as some_numbers.m4a.
    Right click on the item and choose Create AAC version.
    Drag the converted voice onto the desktop.
    Delete the voice copy in iTunes. (important step)
    On desktop, rename the some_number.m4a to something_more_intelligent.m4r
    Drag it back to iTunes and you will find it under Tones.
    Now select it (for sync) and connect your iPhone, do a sync.
    If everything works out, it will be in Settings > Sounds > Ringtone.
    Now choose a contact you want to assign this ringtone, tap Edit and add the ringtone.
    Hope this helps.

  • How can I add an audio file to each slide when I export to HTML Keynote 6.2

    How can I add an audio file to each slide when I export to HTML Keynote 6.2
    I am trying to create an audio slide show instead of a movie

    Drag and drop one music files onto each slide then export. (File > Export > HTML)

  • How can I get my audio book back on my ipad?

    How can I get my audio book back on my ipad?
    After syncing with itunes on the pc, my newly purchased audio books vanished from the ipad, and I can't copy it back! I've tried copying the audio book back into the library, but that didn't help.
    Also couldn't get iTunes on my iCloud! there was no where to select on the icloud dashboard so that I can add iTunes ... Help!

    Audiobooks are not currently available for repeat download from iTunes in the Cloud. Your audiobook should have transferred to your iTunes library when you synced your device.
    You will need to contact support through the "Report a problem" links in your account history, or via Contact Support.
    tt2

  • How can i quick edit Audio( increase bass) of a single file?

    Hi everyone,
    Im new to FCPX. I have a bunch of videos of music gigs ive played and would like to increase the bass (via equalizer) on most of them. All these videos are already converted into an "Apple Friendly" format and are sitting comfortably in my Itunes Video folder. How can i quickly increase the bass in each video (Without having to tediously export one by one) in FCPX and do a quick overwrite over the original video without having to make an EXTRA file?
    THanks

    ok.
    "Why don't you increase the bass with the equalizer in FCP? Do it to one clip and use paste attributes to apply it to other clips."
    1) How do i copy the attributes after making the changes??
    2) How do i paste the attributes onto the next file?
    Thanks.
    Re: How can i quick edit Audio( increase bass) of a single file? 

  • How can i get Beats audio back on my laptop?

    Hello,
    i have Windows 8 on my HP Pavilion dv6. I had Beats audio on it, but then my laptop was doing weird so i had to reset it to factory settings. After that, my laptop was back okay, but Beats audio was gone. My question is: how can i get Beats audio back on my laptop??
    This question was solved.
    View Solution.

    Hi,

  • How can I record an Audio Instrument (saxophone) and listen to a reference track at the same time?

    How can I record an Audio Instrument, and listen to a reference track at the same time?

    Are you using an external audio controller or the line-in and headphone jacks on the side of your computer? You shouldn't have an issue using headphones when you're recording through the line-in but you may want to make sure you have monitoring on and it's going to the right place.
    If you're using an external audio controller, try making an aggregate device combining the controller and the "built-in output" into the same device. Go to Applications/Utilities/Audio MIDI Setup, click the "+" sign at the bottom left to make a new device and check the "use" boxes to the left of the physical devices you want to use as part of that aggregate device. That is how I use the computer's speakers or headphones to monitor my input as opposed to only being able to use the output on my audio controller.
    Now that I see some of the questions on the side of this page I realize that the 13" MBPs seem to have only one combined input/output jack... That is an incredibly stupid feature. What on Earth could possibly justify that design decision? I suppose if that's the problem you're having you'll have to buy some sort of splitter (if they even make them) or get an external audio controller like an Apogee Duet or something along those lines. I would be furious if they combined those two jacks on all of the MBPs.

  • How can I compress a .mov file

    I created a 7.7 GB movie in imovie and I nead to make it fit on a regular 4.7 GB dvd disk.
    Can I turn it into a zip file and use the zip file in idvd. What other ways are there?

    How can I compress a .mov file

Maybe you are looking for

  • My Skype number is not working. No sounds, No rin...

    I really haven't needed it so I have not tried it in months.  But, I tried to add this number to my paypal account and found it wasn't working.  Then I tried to call it.  No sounds at all.  No ringing, no busy signal - nothing. I will not post my num

  • Statistical Delivery Date not apperaing in the Purchase Order

    Hi Gurus, Recently the statistical delivery date(SDD) in the Purchse order has stopped appearing in the PO. Earlier it was appearing but since last one month it has stopped appearing. The field remains blank inspite of sending the message to the vend

  • Mail messages are not visible

    When I open a message in apple mail, the content does not show up. Just the to, From, Title etc. The body of the message is blank. I can sometimes quit mail and relaunch it and see the messages, but not always. It is not consistent with the same mess

  • Slicing and optimising a template in PS CS3?

    Hello, I am just working on a website design in photoshop but now I would like to slice and optimize the template in imageready but I've just noticed that ImageReady is not available any more? Could someone please suggest how I can slice the design u

  • Playing Avid Mpeg 50 Codec in FCP

    Hi I have FCP V7 on Snow Leopard 10.6.6 and have successfully installed the latest Avid PE codec Package for Intel. The Mpeg50 media will now play in QT player, but not in FCP where it says:"Codec not found you may be using a compresssion card withou