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