Byte stream array

Hi,
I have this code:

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;

import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;


public class AudioDataBuffer
{

      /** The size of the temporary read buffer, in frames.
       */
      private static final int      BUFFER_LENGTH = 1024;

      public static void main(String[] args)
            throws Exception
      {
      
            File      sourceFile = new File("C:/Documents and Settings/s118608/Desktop/School/CIS416_PROGRAMMING/Project/dsclip.wav");
            File      targetFile = new File("C:/Documents and Settings/s118608/Desktop/School/CIS416_PROGRAMMING/Project/dsclip.txt");
                        
            /* Get the type of the source file. We need this information
               later to write the audio data to a file of the same type.
            */
            AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(sourceFile);
            AudioFileFormat.Type targetFileType = fileFormat.getType();
            AudioFormat audioFormat = fileFormat.getFormat();
            
            System.out.println("fileFormat "+fileFormat);
            System.out.println("targetFileType "+targetFileType);
            System.out.println("audioFormat "+audioFormat);

            /* Read the audio data into a memory buffer.
             */
            AudioInputStream inputAIS = AudioSystem.getAudioInputStream(sourceFile);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int nBufferSize = BUFFER_LENGTH * audioFormat.getFrameSize();
            byte[]      abBuffer = new byte[nBufferSize];


            /* Here's the byte array everybody wants.
             */
            byte[] abAudioData = baos.toByteArray();
            
            System.out.println("abAudioData "+abAudioData);

            /* And now, write it to a file again.
             */
            ByteArrayInputStream bais = new ByteArrayInputStream(abAudioData);
            AudioInputStream outputAIS = new AudioInputStream(bais, audioFormat,abAudioData.length / audioFormat.getFrameSize());
            int      nWrittenBytes = AudioSystem.write(outputAIS,targetFileType,targetFile);
            System.out.println("nWrittenBytes "+nWrittenBytes);
      }
}

When I run it, I get an output of :

--------------------Configuration: <Default>--------------------
fileFormat WAVE (.wav) file, byte length: 10051, data format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame, , frame length: 10005
targetFileType WAVE
audioFormat ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame,
abAudioData [B@e7b241
nWrittenBytes 46

Process completed.

The problem is this, I want the output of the targetFileType WAVE to be text.
What did I do wrong?

Thanks
Al

lacroix_alAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
can you please make it a little clear actually what you want is that .wav files raw content in a .txt file????
0
lacroix_alAuthor Commented:
What I am looking for is to read the wav file into a buffer.
and write all the data to a text file.
ex.
I need to know all to sample points and there hex addresses.
thanks
Al
0
lacroix_alAuthor Commented:
Does this make sence?
Al
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
hi lacroix_al ,

if you just want to read a WAV file & write its content to a TXT file

here is the code

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class convertwartotxt
{

    public static void main(String[] args)
    {      
        FileReader fr = null;
        FileWriter fw = null;
       
        try
        {
            fr = new FileReader("C:\\CHILD.wav");
                   
            fw = new FileWriter("C:\\out.txt");
           
            int ch = 0;
                 
            while((ch = fr.read()) != -1)
            {    
                System.out.println(Integer.toHexString(ch));
                fw.write(ch);
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }  
        finally
        {
            try
            {
                fr.close();
                fw.close();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }            
        }    
    }
}

just make sure you point to the file correctly.
I think this must be the answer else if you want to use ByteArrayStream you can use it in similar fashion.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
BTW, what is the need to convert the wav to a txt? It will not be readable anyway as all you are doing is creating a new file with the same data but a different extension.
0
lacroix_alAuthor Commented:
shivaspk

Ok this is good.
What I really want to do is match the data points to the hex address and write it to a file.
ex.
7F hex is located at address 1E7A hex.

Thanks
Al
0
lacroix_alAuthor Commented:
Do you understand my question?
Thank
Al
0
lacroix_alAuthor Commented:
Can some PLEASE help me with this.
Al
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.