简体   繁体   English

Android通话录音未录制传入语音

[英]Android Call Recording Incoming voice not getting recorded

I'm working auto call recorder app, I'm able to record voice call on below android 6 using MediaRecorder.AudioSource.VOICE_CALL , From android 6 not able to record voice call using VOICE_CALL .我正在使用自动通话记录器应用程序,我可以使用MediaRecorder.AudioSource.VOICE_CALL在 android 6 以下的系统上录制语音通话,从 android 6 开始无法使用VOICE_CALL录制语音通话。 I managed to record using MediaRecorder.AudioSource.MIC but here incoming voice not getting recorded and I want to record voice call in normal mode not in speaker on mode.我设法使用MediaRecorder.AudioSource.MIC进行录制,但这里传入的语音没有被录制,我想在正常模式下而不是在扬声器开启模式下录制语音通话。 Please help me on this.请帮我解决这个问题。 (I had tried on Xiomi Redmi 4a(android 6),not working). (我曾在小米红米 4a(安卓 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.更新:任何人都知道如何强制另一个流到 MIC 音频源。 This requires native android code.这需要原生安卓代码。 Please help me on this Refer this question for more details on routing audio请帮我解决这个问题,请参阅此问题以获取有关路由音频的更多详细信息

You need to use ndk.您需要使用 ndk。 Here are examples of the functions that need to be done.以下是需要完成的功能的示例。

Load libmedia.so and libutils.so加载 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;}

Function setParameters函数 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;}

Task AudioSetParameters任务 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);
    }
}

There is a library and an example of use https://github.com/ViktorDegtyarev/CallRecLib有一个库和一个使用示例https://github.com/ViktorDegtyarev/CallRecLib

Xiaomi devices always have problems with permission request even run-time or install-time.小米设备即使在运行时或安装时也总是存在权限请求问题。

I have an Xiaomi Redmi 3 pro, and it always force to Deny some permission when I install apps, so I must manually Allow it.我有一个小米红米 3 pro,它在我安装应用程序时总是强制拒绝某些权限,所以我必须手动允许它。 If your problem is the same, I found some workaround solution and it worked for me: How to get MIUI Security app auto start permission programmatically?如果您的问题是相同的,我找到了一些解决方法并且对我有用如何以编程方式获得 MIUI 安全应用程序自动启动权限?

First these 3 permissions are needed in Manifest as well as a runtime permission request if the device is above Marshmallow,首先,Manifest 中需要这 3 个权限,如果设备高于 Marshmallow,则需要运行时权限请求,

<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 is not supported on all phones so you need to continue using MediaRecorder.AudioSource.MIC .并非所有手机都支持MediaRecorder.AudioSource.VOICE_CALL因此您需要继续使用MediaRecorder.AudioSource.MIC

I use this and works fine on most of the devices,我使用它并且在大多数设备上都能正常工作,

      recorder = new MediaRecorder();
      recorder.setAudioSource(audioSource);
      recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
      recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      recorder.setOutputFile(your_path);
  1. You need to set this to record your calls properly,您需要设置此项以正确记录您的通话,

    audioManager.setMode(AudioManager.MODE_IN_CALL);

raise volume level when you start recording开始录音时提高音量

audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL), 0);

When you stop recording set the mode to normal, audioManager.setMode(AudioManager.MODE_NORMAL);当你停止录音时将模式设置为正常, audioManager.setMode(AudioManager.MODE_NORMAL); and also set the stream volume to back how it was.并将流音量设置为支持它的原样。

This could be a Permission related issue.这可能是与权限相关的问题。

With the introduction of Android 6.0 Marshmallow, the app will not be granted any permission at installation time.随着 Android 6.0 Marshmallow 的推出,该应用在安装时将不会被授予任何权限。 Instead, the application has to ask the user for a permission one-by-one at run-time.相反,应用程序必须在运行时逐一询问用户的权限。

I hope you have included the code which explicitly asks for permissions on devices with Marshmallow and above.我希望你已经包含了在棉花糖及更高版本的设备上明确要求权限的代码。

In automatic call recorder (callU) have a option "SoundFX" If Enable Record Calls Two Side在自动通话记录器 (callU) 中有一个选项“SoundFX”如果启用记录通话两侧

Link链接

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM