android上的低音库:如何将音频保存到文件?

时间:2018-04-28 04:11:40

标签: android audio bass

我正在使用低音音频库开发应用程序。关于语音转换功能,我可以像这样成功播放音频, 但是,我无法将其保存到自定义文件中:

BASS.BASS_MusicFree(chan);
        BASS.BASS_StreamFree(chan);
        if ((chan = BASS.BASS_StreamCreateFile(new BASS.Asset(getAssets(), "test.mp3"), 0, 0, BASS.BASS_MUSIC_DECODE)) == 0
                && (chan = BASS.BASS_MusicLoad(new BASS.Asset(getAssets(), "test.mp3"), 0, 0, BASS.BASS_SAMPLE_LOOP | BASS.BASS_MUSIC_RAMP | floatable, 1)) == 0) {
            // whatever it is, it ain't playable
            ((Button) findViewById(R.id.open)).setText("press here to open a file");
            Error("Can't play the file");
            return;
        }

        chan = BASS_FX.BASS_FX_TempoCreate(chan, BASS.BASS_SAMPLE_MONO);//enable pitch
        chanFX = BASS_FX.BASS_FX_TempoGetSource(chan);
        ((Button) findViewById(R.id.open)).setText("test");
        setupFX(mPitch, mRate, mIdistortionListener); 
        BASS.BASS_ChannelPlay(chan, false);
        BASS.BASS_SetVolume(0.9f);

我正在使用低音音频库开发应用程序。关于语音转换功能, 但是,我无法将其保存到自定义文件中:

   mBtnSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String path = testPath();
            savePath(path);
            Toast.makeText(TextActivity.this, "save successfully" + path, Toast.LENGTH_SHORT).show();

        }
    });



    private String testPath() {
    File localFile = new File(Environment.getExternalStorageDirectory().getPath(), "testVoid");
    if (!localFile.exists()) {
        localFile.mkdirs();
    }
    String path = localFile.getAbsolutePath() + "/record" + ".wav";
    Log.d("mvn", path);
    return path;
}



  public void savePath(String filePath) {

    long len = BASS.BASS_ChannelGetLength(chan, BASS.BASS_POS_BYTE);
    double time = BASS.BASS_ChannelBytes2Seconds(chan, len);

    File localFile = new File(filePath);
    //flag=262208
    if ((!isEmpty(filePath)) && (chan != 0) && (BASSenc.BASS_Encode_Start(chan, filePath, 262208, null, Integer.valueOf(0)) != 0)) {
        int i1;
        try {
            ByteBuffer localByteBuffer = ByteBuffer.allocateDirect(20000);
            do {
                i1 = BASS.BASS_ChannelGetData(chan, localByteBuffer, localByteBuffer.capacity());
            } while ((i1 != -1) && (i1 != 0));
            return;
        } catch (Exception localException) {
            localException.printStackTrace();
        }

    }
}

0 个答案:

没有答案