How to cut .wav file by defining start position and end position in android? -
i want specific potion of .wav file in android giving start position , end position. can solve problem in java according answers martin dow. javax.sound* cannot solved in android. android, can opensource project ringdroid project, complicated me cause of beginner android. so, please, suggest , show way me. in advance. here code answered martin dow.
import java.io.*; import javax.sound.sampled.*; class audiofileprocessor { public static void main(string[] args) { copyaudio("/tmp/uke.wav", "/tmp/uke-shortened.wav", 2, 1); } public static void copyaudio(string sourcefilename, string destinationfilename, int startsecond, int secondstocopy) { audioinputstream inputstream = null; audioinputstream shortenedstream = null; try { file file = new file(sourcefilename); audiofileformat fileformat = audiosystem.getaudiofileformat(file); audioformat format = fileformat.getformat(); inputstream = audiosystem.getaudioinputstream(file); int bytespersecond = format.getframesize() * (int)format.getframerate(); inputstream.skip(startsecond * bytespersecond); long framesofaudiotocopy = secondstocopy * (int)format.getframerate(); shortenedstream = new audioinputstream(inputstream, format, framesofaudiotocopy); file destinationfile = new file(destinationfilename); audiosystem.write(shortenedstream, fileformat.gettype(), destinationfile); } catch (exception e) { println(e); } { if (inputstream != null) try { inputstream.close(); } catch (exception e) { println(e); } if (shortenedstream != null) try { shortenedstream.close(); } catch (exception e) { println(e); } } }
Comments
Post a Comment