在Android中使用MediaRecorder和NoiseSuppressor [英] Using MediaRecorder and NoiseSuppressor in Android

查看:753
本文介绍了在Android中使用MediaRecorder和NoiseSuppressor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始一个使用以下代码尝试Android麦克风的项目:

I'm starting off a project experimenting with the Android microphone using code like this:

    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mRecorder.setOutputFile(mFileName);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

在那之后,prepare()和start()开始录制麦克风音频.

After that, a prepare() and start() to begin recording mic audio.

麻烦的是,我正在尝试添加一些音频处理效果,例如NoiseSuppressor. API文档指出,NoiseSuppressor已通过以下方式完成:

Trouble is, I'm trying to also add in some audio processing effects like NoiseSuppressor. The API docs state that NoiseSuppressor is done with this:

 NoiseSuppressor create (int audioSession)

初始化记录流并获取该流的audioSession的合适方法是什么?我很惊讶地发现我无法从mediaRecorder获取audioSession.

What is the appropriate method for initializing the recording stream and getting the audioSession for that stream? I'm surprised to find that I cannot get the audioSession from the mediaRecorder.

为什么存在两种设置音频流的方法?我看到了AudioRecord方法,但是API文档建议上述方法是首选.

Why do two approaches to setting up the audio stream exist? I see the AudioRecord approach, but then the API docs suggest the above approach is preferred.

有什么作用?

推荐答案

来自Android开发人员:

From Android Developers:

要将NoiseSuppressor附加到特定的AudioRecord,请指定 在创建音频记录时,此AudioRecord的音频会话ID 噪声抑制器.通过调用检索音频会话 AudioRecord实例上的AudioRecord.getAudioSessionId().

To attach the NoiseSuppressor to a particular AudioRecord, specify the audio session ID of this AudioRecord when creating the NoiseSuppressor. The audio session is retrieved by calling AudioRecord.getAudioSessionId() on the AudioRecord instance.

这意味着NoiseSuppressor需要audioSessionId来创建这样的噪声抑制器实例

Which means NoiseSuppressor requires audioSessionId to create noise suppressor instance like this

val suppressor = NoiseSuppressor.create(
            recorder!!.audioSessionId)

如果您查看 getaudiosessionid 参考,那么您将看到该音频会话只能由 Media Player Audio Recorder 创建.

因此,您不能将Noise SuppressorMedia Recorder一起使用..但是,平台开发人员可以根据所使用的MediaRecorder.AudioSource默认将Noise Suppressor插入捕获路径中.

Hence you can't use Noise Suppressor along with Media Recorder. However Noise Suppressor can be inserted by default in the capture path by the platform developers according to the MediaRecorder.AudioSource used.

无论如何,如果您仍然想尝试一下Audio Recorder,那么我会说我已经尝试在 Audio Recorder 中启用NS了.当我打电话给NoiseSuppressor.isAvailable()时,它总是返回 false .

Anyways if you still want to give Audio Recorder a try then I would say I already tried to enable NS in Audio Recorder & when I called NoiseSuppressor.isAvailable() it always returned false.

这篇关于在Android中使用MediaRecorder和NoiseSuppressor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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