当用户使用sinch视频通话时,我需要麦克风来录制他说的内容然后翻译。但我不能用麦克风。 有人可以帮帮我吗?
答案 0 :(得分:0)
麦克风一次只能由一个进程使用。您可以使用下面的剪辑
检查Sinch视频通话是否占用了麦克风public static boolean checkIfMicrophoneIsBusy(Context ctx){
AudioRecord audio = null;
boolean ready = true;
try{
int baseSampleRate = 44100;
int channel = AudioFormat.CHANNEL_IN_MONO;
int format = AudioFormat.ENCODING_PCM_16BIT;
int buffSize = AudioRecord.getMinBufferSize(baseSampleRate, channel, format );
audio = new AudioRecord(MediaRecorder.AudioSource.MIC, baseSampleRate, channel, format, buffSize );
audio.startRecording();
short buffer[] = new short[buffSize];
int audioStatus = audio.read(buffer, 0, buffSize);
if(audioStatus == AudioRecord.ERROR_INVALID_OPERATION || audioStatus == AudioRecord.STATE_UNINITIALIZED /* For Android 6.0 */)
ready = false;
}
catch(Exception e){
ready = false;
}
finally {
try{
audio.release();
}
catch(Exception e){}
}
return ready;
}