简体   繁体   中英

Android record sound of our own app

I want to record music playing in my app.like i am playing different sounds with sound pool.Now I want that only soundpool audio is record and save in .wav or mp3 file. I use audio record to record sound.

       AudioRecord audioRecord = new AudioRecord(AudioManager.STREAM_MUSIC,
         44100,
         AudioFormat.CHANNEL_IN_MONO,
         AudioFormat.ENCODING_PCM_16BIT,
         minBufferSize);
   int minBufferSize = AudioRecord.getMinBufferSize(44100, 
         AudioFormat.CHANNEL_IN_MONO, 
         AudioFormat.ENCODING_PCM_16BIT);

       short[] audioData = new short[minBufferSize];
  audioRecord.startRecording();

Now audio is recording but problem is that quality is little bit bad and their is noise also. Now I am stuck kindly help me.

Although i did not find answer of my question, but now i am using technique for recording aspects which i want to share with all of you. Above function which i try to use is totally wrong option when you are trying to save music created by your app at run time. now for my first version i just saving the clicks of piano buttons along with system time in an array. now when i play that clicks it will play same sound as user try to record. i save these notes in database for further reuse by users.although this is not solution because these notes will be played in our app only, but this is good feature which we can add in our app. when i solve the exact solution, i will share with you guys

button.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if(event.getAction()==MotionEvent.ACTION_DOWN){
                    textView.setText("Recording started");
                  startRecording();
                }
                else if(event.getAction()==MotionEvent.ACTION_UP){
                    textView.setText("Recording stopped");
                  stopRecording();
                }
                return false;
            }
        }); 
private void startRecording() {
        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mRecorder.setOutputFile(mFileName);
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

        try {
            mRecorder.prepare();
        } catch (Exception e) {

        }

        mRecorder.start();
    }

    private void stopRecording() {
        mRecorder.stop();
        mRecorder.release();
        mRecorder = null;
        uploadaudio();
    }



You can add this code to record your sound in your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM