首页 文章

Android通话录音未录制来电语音

提问于
浏览
20

我'm working auto call recorder app, I'能够使用 MediaRecorder.AudioSource.VOICE_CALL 在android 6下面录制语音通话,从android 6无法使用 VOICE_CALL 录制语音通话 . 我设法使用 MediaRecorder.AudioSource.MIC 进行录音,但这里传入的声音没有被记录,我想在正常模式下录制语音通话,而不是在扬声器模式下 . 请帮帮我 . (我曾尝试过Xiomi Redmi 4a(android 6),没有工作) .

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);

Edit : There is no issue with permissions.

Update : Anyone knows how to forcing another stream to MIC audio source. This requires native android code. Please help me on this Refer this question for more details on routing audio

6 回答

  • 1

    你需要使用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

  • 1

    小米设备即使在运行时或安装时也始终存在权限请求问题 .

    我有一个小米Redmi 3专业版,当我安装应用程序时它总是强制拒绝一些权限,所以我必须手动允许它 . 如果你的问题是一样的,我找到了一些解决方案,它对我有用:How to get MIUI Security app auto start permission programmatically?

  • 2

    首先,如果设备位于Marshmallow之上,则Manifest需要这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" />
    

    并非所有手机都支持

    • MediaRecorder.AudioSource.VOICE_CALL ,因此您需要继续使用 MediaRecorder.AudioSource.MIC .

    我使用它并在大多数设备上正常工作,

    recorder = new MediaRecorder();
      recorder.setAudioSource(audioSource);
      recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
      recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      recorder.setOutputFile(your_path);
    
    • 您需要将其设置为正确记录您的通话,

    audioManager.setMode(AudioManager.MODE_IN_CALL);

    开始录制时提高音量 audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL), 0);

    当您停止录制时,将模式设置为正常, audioManager.setMode(AudioManager.MODE_NORMAL); 并将流量设置为后退状态 .

  • 10

    这可能是与权限相关的问题 .

    随着Android 6.0 Marshmallow的推出,该应用程序将不会在安装时被授予任何权限 . 相反,应用程序必须在运行时逐个询问用户权限 .

    我希望你已经包含明确要求Marshmallow及以上设备的权限的代码 .

  • 0

    在自动呼叫 Logger (callU)中有一个选项“SoundFX”如果启用记录呼叫双方

    Link

    enter image description here

  • 1

    尝试

    MediaRecorder.AudioSource.VOICE_COMMUNICATION
    

    并看到

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

相关问题