的Android通话录音传入的声音没有得到记录

问题描述:

我工作的自动呼叫记录应用程序,我能记录使用MediaRecorder.AudioSource.VOICE_CALL, 于Android 6无法录制使用VOICE_CALL语音呼叫的语音拨打下面的android 6。我设法使用MediaRecorder.AudioSource.MIC进行录音,但是这里传入的语音没有被录制,我想以正常模式录制语音呼叫而不是在扬声器开启模式下。请帮助我。 (我尝试过Xiomi Redmi 4a(android 6),不工作)。的Android通话录音传入的声音没有得到记录

myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
myRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); 
myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); 
myRecorder.setMaxDuration(60 * 60 * 1000); 
AudioManager audiomanager = 
(AudioManager)getSystemService(AUDIO_SERVICE); 
audiomanager.setMode(2); 

编辑:没有权限的问题。

更新:任何人都知道如何强制另一个流到MIC音频源。这需要原生的android代码。请帮助我 Refer this question for more details on routing audio

+0

你是如何要求的权限? –

+0

@GiacomoLai仅限运行时间! –

+0

嗨,我所有我面临同样的问题(没有得到其他方面的声音)与三星S7和S8其他明智的我编在其他手机上运行得非常好任何想法? –

您需要使用ndk。以下是需要完成的功能的示例。

负载libmedia.so和libutils.so

int load(JNIEnv *env, jobject thiz) { 
    void *handleLibMedia; 
    void *handleLibUtils; 
    int result = -1; 
    lspr func = NULL; 

    pthread_t newthread = (pthread_t) thiz; 

    handleLibMedia = dlopen("libmedia.so", RTLD_NOW | RTLD_GLOBAL); 
    if (handleLibMedia != NULL) { 
     func = dlsym(handleLibMedia, "_ZN7android11AudioSystem13setParametersEiRKNS_7String8E"); 
     if (func != NULL) { 
      result = 0; 
     } 
     audioSetParameters = (lasp) func; 
    } else { 
     result = -1; 
    } 

    handleLibUtils = dlopen("libutils.so", RTLD_NOW | RTLD_GLOBAL); 
    if (handleLibUtils != NULL) { 
     fstr = dlsym(handleLibUtils, "_ZN7android7String8C2EPKc"); 
     if (fstr == NULL) { 
      result = -1; 
     } 
    } else { 
     result = -1; 
    } 

    cmd = CM_D; 

    int resultTh = pthread_create(&newthread, NULL, taskAudioSetParam, NULL); 

    return result;} 

功能setParameters

int setParam(jint i, jint as) { 
pthread_mutex_lock(&mt); 

audioSession = (int) (as + 1); 

kvp = "input_source=4"; 
kvps = toString8(kvp); 

cmd = (int) i; 

pthread_cond_signal(&cnd); 
pthread_mutex_unlock(&mt); 

return 0;} 

任务AudioSetParameters

void *taskAudioSetParam(void *threadid) { 
    while (1) { 
     pthread_mutex_lock(&mt); 
     if (cmd == CM_D) { 
      pthread_cond_wait(&cnd, &mt); 
     } else if (audioSetParameters != NULL) { 
      audioSetParameters(audioSession, kvps); 
     } 
     pthread_mutex_unlock(&mt); 
    } 
} 

有一个图书馆和使用的一个实例https://github.com/ViktorDegtyarev/CallRecLib

+0

@ishmaelMakitla对不起。编辑。 –

+0

嗨@Viktor Degtyarev感谢您的回答,它实际上是在工作。 如果你解释你的答案的解释更有帮助。 (对不起,迟到的回应,其实我正在研究其他项目。) –

+0

嗨维克托将这个库工作在三星S7和S8(Noughat设备),因为我在通话期间记录传入语音时遇到了问题。请帮忙 –

这可能是一个权限相关的问题。

随着Android 6.0 Marshmallow的推出,该应用程序将不会在安装时获得任何许可。相反,应用程序必须在运行时逐一询问用户权限。

我希望你已经包括明确要求在棉花糖和以上设备的权限的代码。

+0

权限,它的记录和创建SD卡中的文件没有问题。事情是我的方声音正在录制,另一方声音不来。 它的工作很好与oneplus 5与android 7 –

首先这些3个权限需要在清单以及如果该设备是上述棉花糖的运行时许可请求,

<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
<uses-permission android:name="android.permission.RECORD_AUDIO" /> 
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" /> 
  1. MediaRecorder.AudioSource.VOICE_CALL上不支持的所有电话,以便您需要继续使用MediaRecorder.AudioSource.MIC
  2. 我用这个和大部分设备工作正常,

    recorder = new MediaRecorder(); 
        recorder.setAudioSource(audioSource); 
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
        recorder.setOutputFile(your_path); 
    
    1. 您需要设置正确记录您的来电,

      audioManager.setMode(AudioManager.MODE_IN_CALL);

    2. 提高音量级别,当你开始录制 audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL), 0);

      当您停止录制时,将模式设置为正常, audioManager.setMode(AudioManager.MODE_NORMAL);并且还设置流量回到原来的状态。

    开始=>
开始=“2”>
+0

感谢您的答案。但传入的语音非常低(声音忽略不计)。 (测试:Xiomi Redmin 4A Android 6) –

+0

您是否正确提高音频管理器的音量?我已经在Redmi Note 3,Samsung Galaxy J2,Coolpad,Samsung Galaxy 2 duos上测试过,它工作正常。 –

+0

@BharathKumar让我知道你是否需要更多的帮助,因为我之前完成了这个任务,并且知道什么可行,哪些不行。 –

小米设备在许可请求甚至运行时或安装时总会遇到问题。

我有一个小米红米3亲,它总是强制拒绝一些权限,当我安装应用程序,所以我必须手动允许它。 如果你的问题是一样的,我发现了一些变通的解决方案,它的工作对我来说:How to get MIUI Security app auto start permission programmatically?

+0

感谢您的回答。但问题是在通话录音期间,其他方声音不能录音。只有我的声音得到记录。 –

+0

你有解决这个问题吗?我也有同样的问题,在三星Galaxy S7,S8 –

+0

你好,我所面临的问题(没有得到其他方面的声音)与三星S7和S8其他明智我的编在其他手机上运行得很好任何想法? –

尝试

MediaRecorder.AudioSource.VOICE_COMMUNICATION 

,看看

https://androidforums.com/threads/android-phone-with-call-recording-function.181663/

+0

感谢您的回答,但此方法也无法正常工作。 –

在自动呼叫记录(callU)有一个选项 “SoundFX” 如果启用通话录音两侧

Link

enter image description here