Pergunta

Am working on a speech recognition app on android, I would like to know how I can read the audio as stream of bytes and play it. Am currently using the below code to start and stop recording.

 void startRecording()
    {
        mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
        mFileName += "/audiorecordtest.mp3";
        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 (IOException e) {
            Log.e(LOG_TAG, "prepare() failed");
        }

        mRecorder.start();
    }

    private void stopRecording()
    {
        mRecorder.stop();
        mRecorder.release();
    }
Foi útil?

Solução

You should use AudioRecord for recording and AudioTrack for playback if you want raw bytes. MediaRecord will give an encoded audio format.

There are plenty of example online if you search for AudioRecord, so I won't go into the details, but it's not very complicated.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top