如何录制声音的机器人?机器人、声音

2023-09-06 01:25:48 作者:酒酿甜心い

我想记录在Android上的声音,但它会创建(SD卡/文件名)的路径上的.mp3文件但是当我运行这个文件时,它doesen't发挥,因为它不记录的声音。

下面是我的code

 公共无效的onClick(视图v){
        // TODO自动生成方法存根
        开关(v.getId()){
        案例(R.id.Button01):
            尝试 {
                //audio.start();
                startRecord用于();
            }赶上(IOException异常E){
                // TODO自动生成的catch块
                e.printStackTrace();
            }
        案例(R.id.Button02):
            //audio.stop();
            STO precord();
        }

    }
     私人无效startRecord用于()抛出IllegalStateException异常,IOException异常{
           //记录=新MediaRecorder();
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC); //确定,所以我说的音源是麦克风,是它的Windows / Linux麦克风上的模拟器?
            recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.AMR_NB);
            recorder.setOutputFile(/ SD卡/音乐/+ System.currentTimeMillis的()+AMR。);
            。录音机prepare();
            recorder.start();
        }

        私人无效STO precord(){
            recorder.stop();
          //recorder.release();
        }



}
 

清单文件

 <使用-权限的Andr​​oid:名称=android.permission.RECORD_AUDIO/>
<使用-权限的Andr​​oid:名称=android.permission.WRITE_EXTERNAL_STORAG​​E/>
 
什么是电话机器人 有什么用

解决方案

参考的录制音频和播放录制的音频Android的音频捕获文档。

I am trying to record the voice in android But it will create the .mp3 file on the path (sdcard/filename) But when i run this file it doesen't play because it doesn't record the voice.

Here is My code

public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()){
        case(R.id.Button01):
            try {
                //audio.start();
                startRecord();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        case(R.id.Button02):
            //audio.stop();
            stopRecord();
        }

    }
     private void startRecord() throws IllegalStateException, IOException{
           // recorder = new MediaRecorder(); 
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);  //ok so I say audio source is the microphone, is it windows/linux microphone on the emulator? 
            recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
            recorder.setOutputFile("/sdcard/Music/"+System.currentTimeMillis()+".amr"); 
            recorder.prepare(); 
            recorder.start();      
        }

        private void stopRecord(){
            recorder.stop();
          //recorder.release();
        }



}

Manifest file

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

解决方案

Refer to the Android Audio Capture documentation for recording audio and playing back the recorded audio.