简体   繁体   English

按下按钮时录制的音频在我的android设备上缺少持续时间

[英]Audio recorded on button press missing some duration on my android device

I am facing an issue that on button touch i start recording audio in my android application, but when i plays the recorded audio it is missing some duration of the recorded audio. 我面临一个问题,即在按钮触摸时我开始在我的android应用程序中录制音频,但是当我播放录制的音频时,它缺少录制的音频的持续时间。

Here is my code snippet to start recording voice on a button touch given by: 这是我的代码段,用于通过以下方式提供的按钮触摸来开始录制语音:

    public void start() {

    myRecorder = new MediaRecorder();
    myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    myRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    myRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
    myRecorder.setOutputFile(outputFile);

    try {
        myRecorder.prepare();

    } catch (IOException e) {
        e.printStackTrace();
    }
    myRecorder.start();
    text.setText("Recording point: Recording...");

}

On sensing touch event i starts calling this start(); 在检测到触摸事件时,我开始调用此start();。 function. 功能。 Can any body tell me any alternative solution? 谁能告诉我任何替代解决方案? I faced this issue on my glaxy s3 android device. 我在Galaxy S3安卓设备上遇到了这个问题。

myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myRecorder.setOutputFile(outputFile);

The piece of code above takes some time, hence the delay between the user pressing the button ( start() being called) and the recorder actually starting the recording ( myRecorder.start() ). 上面的代码需要一些时间,因此用户按下按钮(调用start() )与记录器实际开始记录( myRecorder.start() )之间存在延迟。

You should initialize the recorder and get it ready before the button is pressed. 您应该初始化记录器,并在按下按钮之前准备好它。 Just move the above piece of code elsewhere, eg onCreate() . 只需将上面的代码移到其他位置,例如onCreate() Since I don't know the context of this code, I cannot tell you exactly where. 由于我不知道此代码的上下文,因此无法确切告诉您位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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