1

I am trying to convert audio file to the byte array, but it seems it is not getting converted correctly. I am recording sound using mic, then converting that file to byte array using file's path on the device.

The desired byte array should be like 0x12323

But it is coming like this string [B@14746f6

Below is the code to convert audio to byte array

file is the path of the file on the device. File type is amr

 FileInputStream fis = new FileInputStream(file);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            int read = 0;
            byte[] buffer = new byte[1024];
            while (read != -1) {
                read = fis.read(buffer);
                if (read != -1)
                    out.write(buffer,0,read);
            }
            out.close();

            byte[] bytes = out.toByteArray();
            Log.e("byte array" ,bytes.toString());
12
  • 1
    [B@14746f6 is the default type of string returned by toString Object method. Is not the value (bytes) of the array. Commented Aug 29, 2017 at 12:52
  • if I pass this byte array directly without converting to string then also value passed is the same Commented Aug 29, 2017 at 12:53
  • [B@14746f6 this is being passed, But I want to pass 0x14746f6 like this Commented Aug 29, 2017 at 12:54
  • 1
    I don't know what you have saved in the file but i know that bytes.toString() will not return you the single bytes saved in the array as a string. Commented Aug 29, 2017 at 12:56
  • use this, and see what is the output: Log.e("byte array" , Arrays.toString(bytes)); your code looks good, but as EasyJoin says, you are printing it incorrectly Commented Aug 29, 2017 at 12:58

2 Answers 2

2
String path= ""; // Audio File path
InputStream is= new FileInputStream(path); 
byte[] arr= readByte(is);
Log.e("byte: ",""+ Arrays.toString(arr)); 
Sign up to request clarification or add additional context in comments.

1 Comment

arr is byte array stream it worked for me, may be it help anyone else.
1

I solved this issue after talking to api guy. I converted byte array to base64 string and passed it. Which resolved the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.