在android中编码和解码音频文件的有效方法是什么 我试过下面的 Base64,但解码后文件大小增加了。 编码
ByteArrayOutputStream objByteArrayOS = new ByteArrayOutputStream();
File file = new File(path);
FileInputStream objFileIS;
try {
objFileIS = new FileInputStream(file);
byte[] byteBufferString = new byte[1024];
for (int readNum; (readNum = objFileIS.read(byteBufferString)) != -1;) {
objByteArrayOS.write(byteBufferString, 0, readNum);
System.out.println("read " + readNum + " bytes,");
byte[] bytes = FileUtils.readFileToByteArray(file);
strAttachmentCoded = Base64.encodeToString(bytes,
Base64.DEFAULT);
解码
byte[] decoded = Base64.decode(strAttachmentCoded,
Base64.DEFAULT);
// byte[] decoded1 = Base64.decode(byteBinaryData1, 0);
File file1 = new File(pathAudio);
FileOutputStream os = new FileOutputStream(file1, true);
os.write(decoded);
os.close();
我希望将字符串格式的音频发送到服务器并根据用户要求检索相同的内容。
最佳答案
wikipedia:base64 ( rfc3548 ) 是我认为的正确选择方法。我认为现在最常见的是接管了 wikipedia:uuencoding .
回答问题。 . .
- 您可以添加一些填充。 wikipedia article on base64给出了一个很好的填充示例。
- 或者您可以在您的音频字符串中添加一个 header ,包括长度。 header 还可以包含其他控制数据,因此它可能是您无论如何都想包含的内容。
关于java - 音频文件编解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22596345/