我只想使用底部扬声器播放音频,而只使用设备顶部的麦克风录制音频。我应该如何编写代码?我尝试了很多方法,但是都没有用,问题是两个扬声器都在播放音频。 这是我播放音频的代码的一部分:
aManger = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
aManger.setMode(AudioManager.MODE_NORMAL);
aManger.setSpeakerphoneOn(true);
int bufsize=AudioTrack.getMinBufferSize(48000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);
audio = new AudioTrack(AudioManager.STREAM_MUSIC,
48000,
AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT,
bufsize,
AudioTrack.MODE_STREAM);
这是我录制音频的代码的一部分:
private AudioRecord audioRecord;
private static int audioSource = MediaRecorder.AudioSource.MIC;
//private static int audioSource = MediaRecorder.AudioSource.CAMCORDER;
private static int audioRate = 48000;
// private static int audioChannel = AudioFormat.CHANNEL_IN_MONO;
private static int audioChannel = AudioFormat.CHANNEL_IN_STEREO;
private static int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
private static int inBufferSize =
AudioRecord.getMinBufferSize(audioRate,audioChannel,audioFormat);