在合并音频文件,并在不同的API版本玩奇怪的问题并在、音频文件、奇怪、不同

2023-09-06 01:25:42 作者:人海一粒渣@

所有,我使用的媒体录像机录制音频

案例1:如果我使用 Android版2.2安装设备,我录制的音频混合,玩好

Case 1: If i use Android Version 2.2 installed devices, my recorded audio combined and playing well.

案例2:如果我使用它的 Android 1.6的安装设备,我不能够发挥组合音频文件

Case 2: If i use it in Android 1.6 installed devices, i am not able to play the combined audio file.

这是只打了第一个录制的音频和接下来录制的音频文件保持空没有声音

It is playing only the very first recorded audio and next recorded audio files keep empty no sound.

另外,我的没有得到任何在logcat中误差

我用下面的code录制音频:

I used following code for recording audio :

    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
    mRecorder.setOutputFile(main_record_file);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    mRecorder.prepare();
    mRecorder.start();

此外,我尝试了 mRecorder.setAudioEn codeR(MediaRecorder.AudioEn coder.DEFAULT);

$ C $下结合音频文件:

Code for combining Audio file :

    public void createCombineRecFile(){
    combined_file_stored_path=getFilename_combined_raw(); // File path in String to store recorded audio
    byte fileContent[]=null;
    FileInputStream ins;
    FileOutputStream fos = null;
    try{
        fos = new FileOutputStream(combined_file_stored_path,true);
    }
    catch (FileNotFoundException e1){
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    for(int i=0;i<audNames.size();i++){
        try{
            File f=new File(audNames.get(i));
            Log.v("Record Message", "File Length=========>>>"+f.length());
            fileContent = new byte[(int)f.length()];
            ins=new FileInputStream(audNames.get(i));
            int r=ins.read(fileContent);// Reads the file content as byte from the list.
            Log.v("Record Message", "Number Of Bytes Readed=====>>>"+r);
            fos.write(fileContent);//Write the byte into the combine file.

            Log.v("Record Message", "File======="+i+"is Appended");

        }
        catch (FileNotFoundException e){
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    try{
        fos.close();
        Log.v("Record Message", "===== Combine File Closed =====");
    }
    catch (IOException e){
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

让我知道任何细节need.Thanks。

Let me know any details need.Thanks.

推荐答案

每个音频文件都有它自己的头(包括大约长度/样品等资料) - 通过将文件你生成的文件有多个标题的方式,每个源文件之一(具体取决于使用文件偏移等的确切格式)。 因此,生成的文件是不正确的文件格式规范条款。

Every audio file has its own header (includes information about length/samples etc.) - by combining the files the way you do the resulting file has multiple headers, one per source file (depending on the exact format with file offsets etc.). Thus the resulting file is NOT correct in terms of file format spec.

较新的Andr​​oid版本都更加宽容和工作/与多头present玩......旧版本不...

The newer Android version are more permissive and work/play with "multiple headers" present... the older versions do not...

要创建您必须遵守其中除其他外意味着创建一新标题描述都包含音频规范中的一个正确组合的音频文件...

To create a correctly combined audio file you must conform to the spec which among other things means creating one new header which describes all included audio...

使用的音响组合文件不同的方法 - 通过的ffmpeg为例(见下这个了解如何使FFmpeg的Andr​​oid版)。

Use for the the combination of audio files a different approach - for example via ffmpeg (see this for how to make ffmpeg for android).