固定时间使用麦克风录制数据 [英] Recording data using microphone for a fixed duration

查看:118
本文介绍了固定时间使用麦克风录制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以确定使用手机麦克风的录音时间.就像我单击一个按钮时一样,录音应该开始并且应该在5秒钟后停止,您建议我使用什么方法:-)

I would like to know if there is a way to fix the duration of recording using mobile's microphone. Like when I click a button the recording should start and it should stop after 5 seconds on its own, what method do you propose me to use :-)

很抱歉造成混乱,但是我正在使用AudioRecorder类记录数据,并且我认为MediaRecorder类功能不能(完全)正常工作.

Sorry for the confusion but I am using AudioRecorder class to record data and I don't think the MediaRecorder class function works properly (/at all) for the same.

推荐答案

如果您仅使用计时器,则我认为您无法在应用读取时准确控制缓冲区中的数据量.

If you just use a timer, I do not think that you can accurately control how much data is within the buffer when your app reads it.

我认为他们记录5秒钟音频数据的方法是使用

I think they way to record 5 seconds of audio data is to use the technique from this class.

那里的代码仔细设置了音频缓冲区的大小,以便在记录数据一定时间后会回叫.这是该课程的摘录.

The code there carefully sets the size of the audio buffer so that it will call back after it has recorded data for a certain amount of time. Here is a snipped from that class.

public boolean startRecordingForTime(int millisecondsPerAudioClip,
            int sampleRate, int encoding)
    {
        float percentOfASecond = (float) millisecondsPerAudioClip / 1000.0f;
        int numSamplesRequired = (int) ((float) sampleRate * percentOfASecond);
        int bufferSize =
                determineCalculatedBufferSize(sampleRate, encoding,
                        numSamplesRequired);

        return doRecording(sampleRate, encoding, bufferSize,
                numSamplesRequired, DEFAULT_BUFFER_INCREASE_FACTOR);
    }

然后在您的代码中稍后执行此操作:

Then later on your code just does this:

while (continueRecording)
        {
            int bufferResult = recorder.read(readBuffer, 0, readBufferSize);
//do stuff
        }

由于readBufferSize正确,您将获得所需的数据量(略有变化)

since readBufferSize is just right, you will get the amount of data you want (with some slight variation)

这篇关于固定时间使用麦克风录制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆