Make sound file from byte array?

Ok say I have a program that gets a byte array from a sound file and then randomly removes some of the samples from the array, so that instead of having a value the bytes are just zeroes. I then want to play my new byte array. Here is the code I try to use but when I use it nothing happens.
AudioFormat = ((AudioInputStream) AudioSystem.getAudioInputStream(**The Original Sound File**)).getFormat();
int numBytesRead = 0;
DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, audioFormat);
SourceDataLine sourceDataLineTemp = (SourceDataLine)AudioSystem.getLine(dataLineInfo);
sourceDataLineTemp.write(audioArray, 0, audioArray.length);(Try..catch removed for clarity.)
Also, is it possible to convert a byte array to a .wav sound file?

Im pretty sure if you just write that byte array to disk and open it as a wav file that will do the trick, because thats all a wav file is anyways, a stream of bytes representing audio

Similar Messages

  • How to create PNG file from byte array of RGB value?

    Hi
    Here is my problem.
    I have drawn some sketchs (through code in runtime) on canvas. I have grabbed the RGB information for the drwan image and converted to byte array.
    I have to pass this byte array to server and generate a png file and save.
    Please help.

    {color:#ff0000}Cross posted{color}
    http://forum.java.sun.com/thread.jspa?threadID=5218093
    {color:#000080}Cross posting is rude.
    db{color}

  • Read sound file from disk in Java

    Write a simple application that reads a sound file from disk (use a Clip). Play the sound backwards by arranging the byte arrays/frames in the reverse order.
    Please I need an explanation of every step.
    Get some Duke Dollars for your help.

    Hi,
    When execute this code, I see this: "[Ljava.io.File;@111f71".   
    How I can see the name of the File, and How I can run a program with one by one from the files reader in a parameter ???
      Thank's.
       Hervey P.                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How can I transfer a sound file from my "Voice Memos" app on my iPhone to my iPad?

    How can I transfer a sound file from my "Voice Memos" app on my iPhone to my iPad?

    In iTunes with your iPhone connected, click on the iPhone device, select the Apps tab, scroll down to the File Sharing section and pick an app that plays Quicktimes ("Files Connect" works in this example, but I'm open to suggestions of better apps for playing transferred Quicktimes) and drag your Quicktime from Finder to the Documents pane for the File Sharing app.   Once the file transfer is complete, go to the app on your iPhone to play the Quicktime.

  • Imageicon created from byte array gives -1 height and -1 width...

    Hi,
    when I am trying to create an imageicon object from byte arrays the length and width of the object are coming to be -1.So I am unable to resize the image..
    This is happening for only few images, most of them are working fine and I can resize it...
    What possibly could be wrong??
    ImageIcon imageIcon = new ImageIcon(pImageData) where pImageData is bytearray..
    but I am getting imageIcon.getIconWidth()=-1
    and
    imageIcon.getIconHeight()=-1
    Can anyone help???

    es5f2000 wrote:
    I'm not sure if this is related, but I believe that images which are not currently being rendered return -1, -1 as their size.It is not even correct, so I'm confident it is not related.
    import java.awt.Image;
    import javax.swing.ImageIcon;
    import javax.imageio.ImageIO;
    import java.net.URL;
    class TestIconSize {
         public static void main(String[] args) throws Exception {
              Image image = ImageIO.read( new URL(
                   "http://forums.sun.com/im/silver-star.gif") );
              ImageIcon imageIcon = new ImageIcon( image );
              System.out.println( "Width: " + imageIcon.getIconWidth() );
              System.out.println( "Height: " + imageIcon.getIconHeight() );
    }Output.
    andrew@pc1:/media/disk/projects/numbered/all$ java TestIconSize
    Width: 16
    Height: 16
    andrew@pc1:/media/disk/projects/numbered/all$ The post after yours seems of even more dubious quality. For those (and other) reasons, I second Darryl's call for an SSCCE.

  • Start a sound file from pdf

    Using an iPad, is it possible to play a sound file from a link on a pdf page? If so, is it also possible to stop the file playing when that pdf page is exited?
    Or should I be trying to do this with some other application?
    Any suggestions gratefully received.
    John

    Hi!!
    I guess I had more or less the same problem. Actually, if you want to specify the jar's classpath, you have to put it in the manifest file, or not use the -jar option. Take a look at:
    http://forum.java.sun.com/thread.jsp?forum=22&thread=546391&tstart=0&trange=15
    Once you have the command line, you can use Runtime.exec(...) to run your program.
    I hope it helps...

  • How to import and play sound file from mxl link?

    I need to load different sound files dependent on which link you previously clicked in my app, but cannot figure out how to call the link to the sound file from my mxl file:
    <carRace>http://www.unisux.org/zik-car/lamborghini-diablo-gtr_standing-start.mp3</carRace>
    Can someone tell me what I am doing wrong in this code?
    <fx:Script>
       <![CDATA[
                                            private var req:URLRequest;
                                            private var context:SoundLoaderContext = new SoundLoaderContext(1000);
                                            private var bCall:Sound;
                                            private var bSong:Sound;
      private function playSong():void
                                                      var urlSong:String = "{carRace}";
                                                      var request:URLRequest = new URLRequest(urlSong);
                                                      bSong = new Sound(request, context);
                                                      bSong.play();
      ]]>
    </fx:Script>
    because this code does work:
    <fx:Script>
       <![CDATA[
      private var req:URLRequest;
      private var context:SoundLoaderContext = new SoundLoaderContext(1000);
      private var bCall:Sound;
      private var bSong:Sound;
      private function playSong():void
      var urlSong:String = "http://www.unisux.org/zik-car/lamborghini-diablo-gtr_standing-start.mp3";
                                                      var request:URLRequest = new URLRequest(urlSong);
                                                      bSong = new Sound(request, context);
                                                      bSong.play();
      ]]>
    </fx:Script>

    Visit: http://www.tools.de/solaris/
    you will love sound/audio programming.... source available.

  • How do I read directly from file into byte array

    I am reading an image from a file into a BuffertedImage then writing it out again into an array of bytes which I store and use later on in the program. Currently Im doing this in two stages is there a way to do it it one go to speed things up.
    try
                //Read File Contents into a Buffered Image
                /** BUG 4705399: There was a problem with some jpegs taking ages to load turns out to be
                 * (at least partially) a problem with non-standard colour models, which is why we set the
                 * destination colour model. The side effect should be standard colour model in subsequent reading.
                BufferedImage bi = null;
                ImageReader ir = null;
                ImageInputStream stream =  ImageIO.createImageInputStream(new File(path));
                final Iterator i = ImageIO.getImageReaders(stream);
                if (i.hasNext())
                    ir = (ImageReader) i.next();
                    ir.setInput(stream);
                    ImageReadParam param = ir.getDefaultReadParam();
                    ImageTypeSpecifier typeToUse = null;
                    for (Iterator i2 = ir.getImageTypes(0); i2.hasNext();)
                        ImageTypeSpecifier type = (ImageTypeSpecifier) i2.next();
                        if (type.getColorModel().getColorSpace().isCS_sRGB())
                            typeToUse = type;
                    if (typeToUse != null)
                        param.setDestinationType(typeToUse);
                    bi = ir.read(0, param);
                    //ir.dispose(); seem to reference this in write
                    //stream.close();
                //Write Buffered Image to Byte ArrayOutput Stream
                if (bi != null)
                    //Convert to byte array
                    final ByteArrayOutputStream output = new ByteArrayOutputStream();
                    //Try and find corresponding writer for reader but if not possible
                    //we use JPG (which is always installed) instead.
                    final ImageWriter iw = ImageIO.getImageWriter(ir);
                    if (iw != null)
                        if (ImageIO.write(bi, ir.getFormatName(), new DataOutputStream(output)) == false)
                            MainWindow.logger.warning("Unable to Write Image");
                    else
                        if (ImageIO.write(bi, "JPG", new DataOutputStream(output)) == false)
                            MainWindow.logger.warning("Warning Unable to Write Image as JPEG");
                    //Add to image list
                    final byte[] imageData = output.toByteArray();
                    Images.addImage(imageData);
                  

    If you don't need to manipulate the image in any way I would suggest you just read the image file directly into a byte array (without ImageReader) and then create the BufferedImage from that byte array.

  • How do I store an Int, a short, and multiple bytes from file in byte array

    I'm attempting to do this for a project but can't figure out how to store the three values in one byte array. This is what i've tried
    public void send(byte[] input)
              // TODO
              ByteArrayInputStream bais = new ByteArrayInputStream(input);
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              DataOutputStream dos = new DataOutputStream(baos);
              byte[] pData = new byte[100];
              try {
                   dos.writeShort(checkSum);
                   dos.writeInt(nextSeqNum);
                   pData=baos.toByteArray();
                   bais.read(pData);
              } catch (IOException e) {
              DatagramPacket dgp = new DatagramPacket(pData, pData.length);When i set pData=baos.toByteArray() it changes the size and then stops me from being able to read the other 94 bytes into the array to send. Any ideas?

    You don't need the ByteArrayInputStream at all.
    dos.writeShort(checkSum);
    dos.writeInt(nextSeqNum);
    dos.write(input);
    pData = baos.toByteArray();
    When i set pData=baos.toByteArray() it changes the sizeNo, it makes it refer to a new byte[] array containing what you've written to the BAOS. That's what it's supposed to do.

  • How Do I Load An Animated GIF Into PictureBox Control From Byte Array?

    I'm having a problem with loading an animated GIF int a picturebox control in a C# program after it has been converted to a base64 string, then converted to a byte array, then written to binary, then converted to a base64 string again, then converted to
    a byte array, then loaded into a memory stream and finally into a picturebox control.
    Here's the step-by-step code I've written:
    1. First I open an animated GIF from a file and load it directly into a picturebox control. It animates just fine.
    2. Next I convert the image in the picturebox control (pbTitlePageImage) to a base64 string as shown in the code below:
                    if (pbTitlePageImage.Image != null)
                        string Image2BConverted;
                        using (Bitmap bm = new Bitmap(pbTitlePageImage.Image))
                            using (MemoryStream ms = new MemoryStream())
                                bm.Save(ms, ImageFormat.Jpeg);
                                Image2BConverted = Convert.ToBase64String(ms.ToArray());
                                GameInfo.TitlePageImage = Image2BConverted;
                                ms.Close();
                                GameInfo.TitlePageImagePresent = true;
                                ProjectNeedsSaving = true;
    3. Then I write the base64 string to a binary file using FileStream and BinaryWriter.
    4. Next I get the image from the binary file using FileStream and BinaryReader and assign it to a string variable. It is now a base64 string again.
    5. Next I load the base64 string into a byte array, then I load it into StreamReader and finally into the picturebox control (pbGameImages) as shown in the code below:
    byte[] TitlePageImageBuffer = Convert.FromBase64String(GameInfo.TitlePageImage);
                            MemoryStream memTitlePageImageStream = new MemoryStream(TitlePageImageBuffer, 0, TitlePageImageBuffer.Length);
                            memTitlePageImageStream.Write(TitlePageImageBuffer, 0, TitlePageImageBuffer.Length);
                            memTitlePageImageStream.Position = 0;
                            pbGameImages.Image = Image.FromStream(memTitlePageImageStream, true);
                            memTitlePageImageStream.Close();
                            memTitlePageImageStream = null;
                            TitlePageImageBuffer = null;
    This step-by-step will work with all image file types except animated GIFs (standard GIFs work fine). It looks like it's just taking one frame from the animation and loading it into the picturebox. I need to be able to load the entire animation. Does any of
    the code above cause the animation to be lost? Any ideas?

    There is an ImageAnimator so you may not need to use byte array instead.
    ImageAnimator.Animate Method
    http://msdn.microsoft.com/en-us/library/system.drawing.imageanimator.animate(v=vs.110).aspx
    chanmm
    chanmm

  • How to connect read sound file from chart to Moving STFT PtByPt

    Hi!
    I got a

    Hi sean1985,
    The Sound File Read Simple.vi returns the data as an array of waveforms, while the STFT Spectrogram PtByPt.vi accepts a single waveform.  In order to pass the data from Sound File Read Simple.vi to STFT Spectrogram PtByPt.vi, you will need to index into the array and pass each individual waveform to STFT Spectrogram PtByPt.vi from the array of waveforms that is generated by Sound File Read Simple.vi.
    Thanks,
    Jonathan C
    Staff Application Engineering Specialist | CTD | CLA
    National Instruments

  • Script to make 'delete' file from system and not just library svp.

    I would like something, possibly a script, to replace the delete option in iTunes so that a file deleted from within iTunes is actually deleted from the HDD. I have downloaded a script that can do this but the option ad to be called from the script menu and was not convenient, so I am looking for a way to amend or replace the menu option to achieve this in a natural fashion.

    Okay, here I found this page: http://ask.metafilter.com/18737/How-can-I-make-iTunes-delete-songs-again
    which is nice and informative. What I have found is that in order to delete files natively from within iTunes the default settings of keeping your music files in the iTunes music folder (which can be modified to another directory in iTune's preferences) must be left untouched. This is because iTunes will only delete files from the HDD if they reside in the music folder iTunes refences to. Its a nice structured system that iTunes itself keeps organised so its the better option, as oposed to having files everywhere.
    In order to reset the iTunes dialog messages, the file "com.apple.iTunes.plist" in the "~/Library/Preferences/" dir must be deleted - which resets everything, as the documentation suggests you will know because the copyright agreement will launch when iTunes is started. Please make sure iTunes is off before deleting the file. The documentation also suggests deleting another file but I didn't do this and it worked for me.
    However the ability to delete movies from the HDD is not an option from within iTunes, I suggest finding a script that will move all movies in a certain playlist to the recycle bin folder

  • How can I transfer or make readable files from one user to another on the same iMac

    I have migrated files from a windows PC to my Imac. The transferred files have been saved successfully against a new user (which I can access). How can I make those files available to the all users of my Imac?

    In FINDER, drag and drop the files into the Public Folder.  All Users can then access those files.
    Hope this helps

  • Find keyword in XML file from an array of keywords

    Hi,
    I have an array of collection of keyword:
    $KeyWord = @("Fail","Exception","Terminated","Error")
    I want to check in a textfile sample.xml, if any or all keywords from the array $KeyWord exist. If any of the keyword exist in the textfile, a boolean variable $ExceptionOccurred will return $true.
    The code I am using working good with a TEXT file, but not working with XML file. Is there a way to convert XML to Text and then look for keyword in plaintext?
    Code:
    $KeyWord = @("Fail","Exception","Terminated","Error")
    $sampleFile = Get-Content .\file1.txt
    $ExceptionOccurred = $false
    $KeyWord | ForEach {
        If ($sampleFile -contains $_) {
            $ExceptionOccurred = $true
    $ExceptionOccurred

    hello,
    with PowerShell you can parsing XML files.
    Example XML-File:
    <ListOfData><Table><service>Backup1</service><description>Backup</description><status>Fail</status></Table><Table><service>Backup2</service><description>Backup</description><status>Exception</status></Table><Table><service>Backup2</service><description>Backup</description><status>Error</status></Table></ListOfData>
    with Select-Object you expand the XML as Table and ForEach-Object with if match the attribute "status" for value in the $KeyWord array.
    $KeyWord = @("Fail","Exception","Terminated","Error")[xml]$xml = Get-Content .\file.xml$xml.ListOfData | Select-Object -ExpandProperty Table | ForEach-Object{if($KeyWord -contains $_.status){$ExceptionOccurred = $true}}

  • How do I import video and sound files from a hard drive into Final Cut Pro X?

    I just installed the lastest upgrade to Final Cut Pro X.  I have an external hard drive connected to my computer and I want to import video and sound files into Final Cut Pro X- how do I make the transfer? 

    File>Import Files (Shift-Cmd-I). Select the files, fill out the dialog box that appears as you need.

Maybe you are looking for

  • How to delete the folder in ABAP

    Hi all, i am dowmloading one text file into a one particular folder using GUI_download function module. and whenever we are downloading the text files to that particular folder i have to check whether the folder is exist or not, if that folder is exi

  • Create a ThreadQueue programatically

    Is there any way to create ExecuteQueue in weblogic 8.1 programatically. As we know weblogic create ExecuteQueue for us on the basis of config.xml, I want to create ThreadQueue thru my program and use it in my program which runs inside app server. Th

  • Rush Order & RLT

    Hi All, am currently using RLT, i would like to control the rush orders from consuming the stock reserved by the sales orders available in the system already. note : i cannot exclude the sales requirements from delivery scope of availability check, b

  • Calculator and clock on desktop

    I want to add world clock and calculator which is their in dashboard to my desktop how to do?

  • Updates Fail to install

    The following updates fail to install: CS5 4.0.5 updates Extension Manager CS5 5.0 update Photoshop 12.0.4 update for CS5 Photoshop Camera RAW 6.7 update I recently bought a Nikon D7000 and my CS5 with Camera RAW 6.0.8.205 won't read it!