在Android手机上录制语音

时间:2010-12-09 04:41:45

标签: android mobile voice-recording

我想在Android手机上录制语音,我不知道如何做到这一点。我搜索了很多但找不到任何有用的东西。

任何人都可以解决这个问题。

谢谢, 大卫

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

取决于你想要的声音^^

如果你想做一个备忘录/录音机应用程序,请继续阅读

如果您尝试录制对话,那么至少在当时是不可能的(相信我,我花1个月时间与同事一起搜索)。

所以如果你想录制你的声音,试试这个:

public class StreamerAudio implements Runnable {

    private static FileOutputStream fOut;
    public static boolean isRecording = false;
    private int buffersize;
    private static AudioRecord arec;

    private int encoding = AudioFormat.ENCODING_PCM_16BIT; 
    private int audioChannel = AudioFormat.CHANNEL_CONFIGURATION_DEFAULT;

    private int audioSource = MediaRecorder.AudioSource.VOICE_DOWNLINK;


    private static MicProject parent = null;

    public StreamerAudio(MicProject parent_){
        this.parent = parent_;
    }

    @Override
    public void run() {
        //openFile();

        buffersize = (int) AudioRecord.getMinBufferSize(11025,audioChannel,AudioFormat.ENCODING_PCM_16BIT);
        arec = new AudioRecord(audioSource,
                11025,
                audioChannel,
                encoding,
                buffersize);
        byte[] buffer = new byte[buffersize];
        byte[] buffer2 = new byte[buffersize];
        byte[] bufferSwap = buffer;

        arec.startRecording();

        isRecording = true;

        while(isRecording) {
            arec.read(buffer, 0, buffersize);
                printBuffer(buffer);
        }  
    }

    public void printBuffer(byte[] buffer) {
        try {
            parent.setBufferToDisplay(buffer);
        } catch (Exception e) {

}