音频文件编码和解码 [英] Audio File Encoding and Decoding

查看:161
本文介绍了音频文件编码和解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是有效的方式连接code和德code android系统中的音频文件
我曾尝试为Base64如下解码,但文件大小增加得到后。
恩code

What is the efficient way to encode and decode an audio file in android I have tried the Base64 as below but after decoding the file size get increased. Encode

 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);

德code

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();

我想在字符串格式的音频发送到服务器并检索同样按照用户的要求。

i want audio in String format to send to server and retrieve the same as per the user requirement.

推荐答案

百科:BASE64 rfc3548 )是选择我认为合适的方法。现在最常见的,我认为具有维基百科接管。uuencoding

wikipedia:base64 (rfc3548) is the right method to choose I would think. It is most common now I think having taken over from wikipedia:uuencoding.

要回答这个问题。 。 。

To answer the question . . .


  1. 您可以添加一些填充。上的base64的维基百科的文章给人填充一个很好的例子。

  2. 或者你可以添加一个头音频线,包括长度。头部还可以包括其他控制数据,因此它可能是您无论如何要包括的东西。

  1. You could add some padding. The wikipedia article on base64 gives a good example of padding.
  2. Or you could add a header to your audio string including length. The header could also include other control data so it may be something you want to include anyway.

这篇关于音频文件编码和解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆