15
R-C-D
6y

Hi devs!
I've seeked the world but found no answer to this:
I want an android code to convert double[] to a sound file and be able to get that double[] from the file.
And yes I've tried stdAudio library but it did not work as I expected.

Give a replay, save my life 😁

Comments
  • 1
    public void writeToFile(byte[] array) {
    try {
    String path = "Your path.mp3";
    File file = new File(path);
    if (!file.exists()) {
    file.createNewFile();
    }
    FileOutputStream stream = new FileOutputStream(path);
    stream.write(array);
    }
    catch (FileNotFoundException e1) { e1.printStackTrace(); } }
  • 0
    @hube thaaaaaanksssss!!!!
    But how can i read back those doubles?
  • 1
    @R1100 @hube Calling a file an MP3 doesn't make it one, that format is somewhat close to a WAVE file. But if you want no loss, writing your buffer directly into a file is the simplest way. To read it back, FileInputStream should do the job. Make sure your casts don't destroy your data. If your byte array isn't 8 times the length of your double array, you can be sure something isn't going the way you want
  • 1
    @R1100 https://stackoverflow.com/questions...

    Too lazy to write anything
  • 1
    @CptFox he never said he wanted a fully functional (compressed) mp3 file, i only read that he wanted to have some kind of array, here a double array, not even bytes, store it in a simili-mp3 file then get them back
Add Comment