Android如何将音轨写入sd卡作为mp3或其他音频格式

时间:2014-09-25 07:59:38

标签: android audio mp3 sd-card

基本上我需要更改录音,然后将效果添加到声音然后分享效果 总之,用添加效果分享声音     void playRecord(){

        File file = new File(Environment.getExternalStorageDirectory(),
                "testaudio.pcm");
        // File file = new File(Environment.getExternalStorageDirectory(),
        // "testaudio.3gp");

        int shortSizeInBytes = Short.SIZE / Byte.SIZE;

        int bufferSizeInBytes = (int) (file.length() / shortSizeInBytes);
        short[] audioData = new short[bufferSizeInBytes];

        try {
            InputStream inputStream = new FileInputStream(file);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(
                    inputStream);
            DataInputStream dataInputStream = new DataInputStream(
                    bufferedInputStream);

            int i = 0;
            while (dataInputStream.available() > 0) {
                audioData[i] = dataInputStream.readShort();
                i++;
            }



            dataInputStream.close();

            // int sampleFreq = (Integer) spFrequency.getSelectedItem();
            int sampleFreq = 11025;
            AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
                    sampleFreq, AudioFormat.CHANNEL_CONFIGURATION_MONO,
                    AudioFormat.ENCODING_PCM_16BIT, bufferSizeInBytes,
                    AudioTrack.MODE_STREAM);

            audioTrack.play();
            // audioTrack.reloadStaticData()
            audioTrack.write(audioData, 0, bufferSizeInBytes);



        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

在此我需要将此audioTrack保存为我的SD卡,如mp3或waw等音频格式

0 个答案:

没有答案