可以在Android模拟器录制和播放音频使用PC硬件?模拟器、音频、硬件、Android

2023-09-12 00:39:18 作者:梨叶茶

我没有一款Android手机,但我想反正要开发它。此刻来测试我的应用程序的唯一方法是使用仿真器,这是我读过不支持音频录制。但是,我读到了启动命令 - 音频,允​​许音频输入/从你的电脑使用winaudio后端输出。我一直没能得到它的工作,虽然,是有可能使用我的电脑的麦克风录制?如果是的话,我究竟哪里做错了?

I don't have an android phone, but i'm trying to develop for it anyway. The only way to test my application at the moment is to use the emulator, which I've read does not support audio recording. However, I read about the startup command "-audio " which allows audio input/output from your pc using the 'winaudio' backend. I haven't been able to get it to work though, is it possible to record using my pc's microphone? If so, what am I doing wrong?

推荐答案

录制音频可能至少在标准2.3.3仿真器上的Windows 7;我已经尝试过了,它的工作原理。但是,录制的音频没有在我的案件听起来有点怪(慢)。我没有调查的原因。

Recording audio is possible at least in the standard 2.3.3 emulator on Windows 7; I have tried it and it works. However, the recorded audio did sound a bit weird (slow) in my case. I did not investigate the cause.

您需要录音+播放支持添加到该仿真器(Android SDK和AVD管理器 - >虚拟设备 - >编辑 - >硬件 - >新建)。然后用[MediaRecorder API] [1]录制(MediaRecorder.AudioSource.MIC)。

You need to add audio recording + playback support to the emulator (Android SDK and AVD manager -> Virtual devices -> Edit -> Hardware -> New). Then use the [MediaRecorder API][1] to record (MediaRecorder.AudioSource.MIC).

code是:

fMediaRecorder= new MediaRecorder();
fMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
fMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
fMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

fMediaRecorder.setAudioChannels(1);
fMediaRecorder.setAudioSamplingRate(8000);

fMediaRecorder.setOutputFile(fTmpFile.getAbsolutePath());

fMediaRecorder.prepare();

fMediaRecorder.start();

您还需要

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

的Andr​​oidManifest.xml

对我的作品,但音频失真。

Works for me, but Audio IS distorted.