Connecting Tech Pros Worldwide Forums | Help | Site Map

audio file problem

Member
 
Join Date: Mar 2008
Posts: 36
#1: Oct 9 '08
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's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168
#2: Oct 9 '08

re: audio file problem


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.
Member
 
Join Date: Mar 2008
Posts: 36
#3: Oct 9 '08

re: audio file problem


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

Expand|Select|Wrap|Line Numbers
  1. public void messagencode(String message,File file) throws
  2.   Exception
  3.   {
  4.       len= message.length();
  5.       char chmess[] = new char[len];
  6.       message.getChars(0,len,chmess,0);
  7.       InputStream ins = new FileInputStream(file);
  8.       OutputStream outs = new FileOutputStream(new File("c:/steged.wav"));
  9.       byte b[]=new byte[1];
  10.       for(int i=0;i<len+1;i++)
  11.       {
  12.  
  13.               String slen=String.valueOf(chmess[i-1]);
  14.              byte bmes[]=slen.getBytes();
  15.               outs.write(bmes);
  16.                int n=ins.read(b);
  17.       }
  18.       while(true)
  19.       {
  20.       int i=ins.read();
  21.       if(i==-1) break;
  22.       outs.write(i);
  23.       }
  24.       ins.close();
  25.       outs.close();
  26.   }

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
Member
 
Join Date: Mar 2008
Posts: 36
#4: Oct 9 '08

re: audio file problem


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

Expand|Select|Wrap|Line Numbers
  1. public void messagencode(String message,File file) throws
  2.   Exception
  3.   {
  4.       len= message.length();
  5.       char chmess[] = new char[len];
  6.       message.getChars(0,len,chmess,0);
  7.       InputStream ins = new FileInputStream(file);
  8.       OutputStream outs = new FileOutputStream(new File("c:/steged.wav"));
  9.       byte b[]=new byte[1];
  10.       for(int i=0;i<len;i++)
  11.       {
  12.  
  13.               String slen=String.valueOf(chmess[i]);
  14.              byte bmes[]=slen.getBytes();
  15.               outs.write(bmes);
  16.                int n=ins.read(b);
  17.       }
  18.       while(true)
  19.       {
  20.       int i=ins.read();
  21.       if(i==-1) break;
  22.       outs.write(i);
  23.       }
  24.       ins.close();
  25.       outs.close();
  26.   }

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
Member
 
Join Date: Mar 2008
Posts: 36
#5: Oct 9 '08

re: audio file problem


read the second one th
myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168
#6: Oct 9 '08

re: audio file problem


Quote:

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.
Reply