java - Converting Image-->Sound--->Record sound---->Image -


i creating program following:

  1. convert image(png) sound(wav).
  2. playing , recording sound.
  3. reproducing image sound.

the program uses red(from rgb) values of image , put them in wave file this:

consider following words red pixel values in image:

a1 a2 a3 a4  b1 b2 b3 b4  c1 c2 c3 c4       (i using square image)  d1 d2 d3 d4 

it puts them in wave file this:

a1 a2 a3 a4 b1 b2 b3 b4 c1 c2 c3 c4 d1 d2 d3 d4 

problem when sound plays , record starting time , ending time of recording need same of sound produced program(which never possible) otherwise pixels displace like:

xx xx a1 a2  a3 a4 b1 b2  b3 b4 c1 c2  c3 c4 d1 d2 

you idea right!!

here's partial code using convert image sound:

imgbuffer = imageio.read(new file("d:\\sound_to_image.png")); int[][][] pixels = new int[width][height][3]; loop ( c = new color(imgbuffer.getrgb(i,j)); pixels[i][j][0] = c.getred(); ) 

//--------------creating long 1d array 2d array

byte buf[]=new byte[width*height+1]; loop ( buf[ptr]=(byte)(pixels[x][y][0]); )  bytearrayinputstream bais =new bytearrayinputstream(buf); audioformat format = new audioformat(20000f, 8, 1, true, false); file file = new file("d:\\image_to_sound.wav"); long length = (long)(buf.length / format.getframesize()); audioinputstream audioinputstreamtemp = new audioinputstream(bais, format, length); audiosystem.write(audioinputstreamtemp, type.wave, file); 

and code sound image is:

audioinputstream ais=audiosystem.getaudioinputstream(wavfile); byte[] data=new byte[ais.available()]; ais.read(data); 

//----------------one side producing square image , image writing

int oneside = (int)math.ceil(math.sqrt((double)data.length)); int temp = data.length; system.out.println("lnght="+data.length+"and sqr="+oneside*oneside); bufferedimage img= new bufferedimage(oneside, oneside, bufferedimage.type_int_rgb);  loop ( color c2=new color(math.abs(data[ptr]),0, 0 ); img.setrgb(i, j, c2.getrgb()); ) 

any appreciated. stuck @ on month.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -