本文介绍了如何从话筒直接在Android上播放声音音箱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序,我需要从话筒直接到扬声器的直接声音。没有其他动作。我找到了一种方法通过播放文件,并设置扬声器关直接从话筒听筒声音。所以我想音箱同样可以正常工作。但是我不知道如何摆脱正在播放的文件的事情。谢谢你。
扬声器(){
m_audioManager =(AudioManager)getSystemService(Context.AUDIO_SERVICE);
m_audioManager.setSpeakerphoneOn(真正的); //没有必要,我认为
//m_audioManager.setRouting(AudioManager.MODE_NORMAL,AudioManager.ROUTE_EARPIECE,AudioManager.ROUTE_ALL);听筒需要这个?
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
m_audioManager.setMode(AudioManager.MODE_IN_CALL);
解决方案
使用AudioRecord和放大器; AudioTrack记录和放大器;玩(改变,如果扬声器需要..._音乐
静态最终诠释BUFFERSIZE = 200000;
最终短[]缓冲区=新的短[BUFFERSIZE]
短[] readBuffer =新的短[BUFFERSIZE]
公共无效的run(){
isRecording = TRUE;
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
INT缓冲区大小= AudioRecord.getMinBufferSize(11025,AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_16BIT);
AREC =新AudioRecord(MediaRecorder.AudioSource.MIC,11025,AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_16BIT,缓冲区大小);
atrack =新AudioTrack(AudioManager.STREAM_VOICE_CALL,11025,AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_16BIT,缓冲区大小,AudioTrack.MODE_STREAM);
atrack.setPlaybackRate(11025);
byte []的缓冲区=新的字节[缓冲区大小]
arec.startRecording();
atrack.play();
而(isRecording){
arec.read(缓冲液,0,缓冲区大小);
atrack.write(缓冲液,0,buffer.length);
}
}
in my application, I need to direct sound from microphone directly to speaker. No other actions.I found a way to direct sound from microphone to earpiece by playing a file and setting speaker off. So I guess speaker can work similarly. However I don' know how to get rid of the playing file thing. Thank you.
speaker() {
m_audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
m_audioManager.setSpeakerphoneOn(true); // not needed I think
//m_audioManager.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL); earpiece need this?
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
m_audioManager.setMode(AudioManager.MODE_IN_CALL);
解决方案
use AudioRecord & AudioTrack to record & play (change to ..._MUSIC if speaker needed
static final int bufferSize = 200000;
final short[] buffer = new short[bufferSize];
short[] readBuffer = new short[bufferSize];
public void run() {
isRecording = true;
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
int buffersize = AudioRecord.getMinBufferSize(11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT);
arec = new AudioRecord(MediaRecorder.AudioSource.MIC, 11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, buffersize);
atrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL, 11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, buffersize, AudioTrack.MODE_STREAM);
atrack.setPlaybackRate(11025);
byte[] buffer = new byte[buffersize];
arec.startRecording();
atrack.play();
while(isRecording) {
arec.read(buffer, 0, buffersize);
atrack.write(buffer, 0, buffer.length);
}
}
这篇关于如何从话筒直接在Android上播放声音音箱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!