audio file problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pankajs
    New Member
    • Mar 2008
    • 36

    #1

    audio file problem

    hello !

    i m reading a wav file by int b=ins.read(); and writing b on other wav file by
    outs.write(b); in a loop until b==-1
    where
    InputStream ins = new FileInputStream ("C:/audio.wav");
    OutputStream outs = new FileOututStream (new File("c:/audio1.wav"));
    its playing
    but when i write something to output file in byte form having some value from my own it does not play
    eg. byte b[] = new byte[1];
    and b[0] having some value 123 and writing b by
    outs.write(b); at some place and copying other as it is.
    it show an error when on playing ie. cannot create audio stream from input stream
    what is the problem with this? can anyone help me out?
  • myusernotyours
    New Member
    • Nov 2007
    • 188

    #2
    Hi,

    We cannot help you out if we have to struggle to understand what you are trying to do.

    Just put your question nicely and put the code between tags then it will be easier for all of us.

    Regards,

    Alex.

    Comment

    • pankajs
      New Member
      • Mar 2008
      • 36

      #3
      i m working on embedding a text message in a wav file. To do it we have to first read the audio file(wav) , there is method a read() to read the file and a method write(b) to write a audio file where b is a byte having some data.
      Here is the code

      Code:
      public void messagencode(String message,File file) throws
        Exception
        {
      	  len= message.length();
      	  char chmess[] = new char[len];
      	  message.getChars(0,len,chmess,0);
      	  InputStream ins = new FileInputStream(file);
      	  OutputStream outs = new FileOutputStream(new File("c:/steged.wav"));
      	  byte b[]=new byte[1];
      	  for(int i=0;i<len+1;i++)
      	  {
      
      		 	 String slen=String.valueOf(chmess[i-1]);
      			 byte bmes[]=slen.getBytes();
      			  outs.write(bmes);
      	 	 	 int n=ins.read(b);
      	  }
      	  while(true)
      	  {
      	  int i=ins.read();
      	  if(i==-1) break;
      	  outs.write(i);
      	  }
      	  ins.close();
      	  outs.close();
        }

      in this code firstly byte form a text message is written on steged.wav, then in the while(true) loop what is being done is that audio file is copied in steged.wav


      But the problem is that when try to play steged.wav it shows an error ie.
      could not create audio stream from input stream


      But second thing is that when we only copied a wav file just applying while loop as above, it playing

      Comment

      • pankajs
        New Member
        • Mar 2008
        • 36

        #4
        i m working on embedding a text message in a wav file. To do it we have to first read the audio file(wav) , there is method a read() to read the file and a method write(b) to write a audio file where b is a byte having some data.
        Here is the code

        Code:
        public void messagencode(String message,File file) throws
          Exception
          {
        	  len= message.length();
        	  char chmess[] = new char[len];
        	  message.getChars(0,len,chmess,0);
        	  InputStream ins = new FileInputStream(file);
        	  OutputStream outs = new FileOutputStream(new File("c:/steged.wav"));
        	  byte b[]=new byte[1];
        	  for(int i=0;i<len;i++)
        	  {
        
        		 	 String slen=String.valueOf(chmess[i]);
        			 byte bmes[]=slen.getBytes();
        			  outs.write(bmes);
        	 	 	 int n=ins.read(b);
        	  }
        	  while(true)
        	  {
        	  int i=ins.read();
        	  if(i==-1) break;
        	  outs.write(i);
        	  }
        	  ins.close();
        	  outs.close();
          }

        in this code firstly byte form a text message is written on steged.wav, then in the while(true) loop what is being done is that audio file is copied in steged.wav


        But the problem is that when try to play steged.wav it shows an error ie.
        could not create audio stream from input stream


        But second thing is that when we only copied a wav file just applying while loop as above, it playing

        Comment

        • pankajs
          New Member
          • Mar 2008
          • 36

          #5
          read the second one th

          Comment

          • myusernotyours
            New Member
            • Nov 2007
            • 188

            #6
            Originally posted by pankajs

            But the problem is that when try to play steged.wav it shows an error ie.
            could not create audio stream from input stream


            But second thing is that when we only copied a wav file just applying while loop as above, it playing
            It seems you are messing up the file format while appending the message. Usually such files have specific formats and you can't just append data arbitrarily.

            You will need to know the file format before you can tinker with the file. Just search google for the format specification.

            Regards,

            Alex.

            Comment

            Working...