通话录音 - 使其在 Nexus 5X 上工作(可以生根或自定义 ROM) [英] Call recording - make it work on Nexus 5X (rooting or custom ROM possible)
问题描述
我正在尝试在 Nexus 5X、Android 7.1(我自己的 AOSP 版本)上使用 AudioRecord
和 AudioSource.VOICE_DOWNLINK
.
我已经过了权限阶段 - 将我的 APK 移至特权应用,对 Android 源中的 AudioRecord
进行了调整,以停止抛出有关此源的异常.
现在我在打电话时得到了空的录音缓冲区.
我知道有很多通话录音应用,它们可以在其他设备上运行.我还看到某些应用程序可以对有根的 N5 进行一些破解并使其正常工作.
我希望在 Nexus 5X 上实现相同的效果 - 任何调整对我来说都可以,包括更改 Android 版本、修改 Qualcomm 驱动程序、设备配置文件等 - 基本上可以在自定义 ROM 中实现的任何操作.
我尝试过处理平台代码 - hardware/qcom/audio/hal/voice.c,尤其是函数 voice_check_and_set_incall_rec_usecase
,但到目前为止还没有弄明白.>
还查了device/lge/bullhead/mixer_paths.xml,发现有一段跟通话录音相关的:
<ctl name="MultiMedia1 Mixer VOC_REC_UL" value="0"/><ctl name="MultiMedia1 Mixer VOC_REC_DL" value="0"/><ctl name="MultiMedia8 Mixer VOC_REC_UL" value="0"/><ctl name="MultiMedia8 Mixer VOC_REC_DL" value="0"/><!-- 通话录音结束-->
但我也无法理解它或如何提供帮助.
不确定是否是 Nexus 5 特定问题,但通常用于记录通话的类是 MediaRecorder
.您是否尝试过将 AudioRecorder
替换为 MediaRecorder
?
基于 this 堆栈溢出问题,我想你可以试试以下代码基于 Ben 博客文章:
import android.media.MediaRecorder;导入 android.os.Environment;导入 java.io.File;导入 java.io.IOException;公共类 CallRecorder {最终的 MediaRecorder 记录器 = new MediaRecorder();最终字符串路径;/*** 在给定的路径(相对于 SD 卡的根目录)创建一个新的录音.*/公共 CallRecorder(字符串路径){this.path = sanitizePath(path);}私人字符串消毒路径(字符串路径){if (!path.startsWith("/")) {路径=/"+路径;}if (!path.contains(".")) {路径 += ".3gp";}返回 Environment.getExternalStorageDirectory().getAbsolutePath() + 路径;}/*** 开始新的录音.*/public void start() 抛出 IOException {字符串状态 = android.os.Environment.getExternalStorageState();如果(!state.equals(android.os.Environment.MEDIA_MOUNTED)){throw new IOException("SD 卡没有挂载.它是" + state + ".");}//确保我们计划存储录音的目录存在文件目录 = new File(path).getParentFile();如果 (!directory.exists() && !directory.mkdirs()) {throw new IOException("无法创建文件路径.");}recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);recorder.setOutputFile(path);recorder.prepare();录音机开始();}/*** 停止先前已开始的记录.*/public void stop() 抛出 IOException {recorder.stop();recorder.release();}}
在此示例中,我使用了 MediaRecorder.AudioSource.VOICE_CALL
但您可以测试其他选项,例如 MediaRecorder.AudioSource.VOICE_COMMUNICATION
以及麦克风,看看是否您的手机存在任何硬件问题.
I'm attempting to use AudioRecord
with AudioSource.VOICE_DOWNLINK
on Nexus 5X, Android 7.1 (my own build from AOSP).
I'm already past the permissions stage - moved my APK to privileged apps, made an adjustment to AudioRecord
in Android source to stop throwing an exception about this source.
Now I'm getting empty recording buffers during a phone call.
I know that there are a lot of call recording apps, and they work on other devices. I've also seen certain apps that can perform some hack on a rooted N5 and make it work.
I wish to achieve the same on Nexus 5X - ANY adjustment is OK for me, including changing Android version, modifying Qualcomm drivers, device configuration files, etc. - basically anything that can be achieved in a custom ROM.
I've tried messing around with platform code - hardware/qcom/audio/hal/voice.c, especially the function voice_check_and_set_incall_rec_usecase
, but could not make sense out of it so far.
Also checked device/lge/bullhead/mixer_paths.xml, found there's a section related to call recording:
<!-- Incall Recording -->
<ctl name="MultiMedia1 Mixer VOC_REC_UL" value="0" />
<ctl name="MultiMedia1 Mixer VOC_REC_DL" value="0" />
<ctl name="MultiMedia8 Mixer VOC_REC_UL" value="0" />
<ctl name="MultiMedia8 Mixer VOC_REC_DL" value="0" />
<!-- Incall Recording End -->
But I also couldn't make sense out of it or how it can be helped.
Not sure if it is a Nexus 5 specific issue but usually the class used to record calls is MediaRecorder
. Have you tried to replace AudioRecorder
by a MediaRecorder
?
Based on this stack-overflow question, I think you could try the following code based on Ben blog post:
import android.media.MediaRecorder;
import android.os.Environment;
import java.io.File;
import java.io.IOException;
public class CallRecorder {
final MediaRecorder recorder = new MediaRecorder();
final String path;
/**
* Creates a new audio recording at the given path (relative to root of SD card).
*/
public CallRecorder(String path) {
this.path = sanitizePath(path);
}
private String sanitizePath(String path) {
if (!path.startsWith("/")) {
path = "/" + path;
}
if (!path.contains(".")) {
path += ".3gp";
}
return Environment.getExternalStorageDirectory().getAbsolutePath() + path;
}
/**
* Starts a new recording.
*/
public void start() throws IOException {
String state = android.os.Environment.getExternalStorageState();
if(!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
throw new IOException("SD Card is not mounted. It is " + state + ".");
}
// make sure the directory we plan to store the recording in exists
File directory = new File(path).getParentFile();
if (!directory.exists() && !directory.mkdirs()) {
throw new IOException("Path to file could not be created.");
}
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
recorder.prepare();
recorder.start();
}
/**
* Stops a recording that has been previously started.
*/
public void stop() throws IOException {
recorder.stop();
recorder.release();
}
}
In this sample, I've used MediaRecorder.AudioSource.VOICE_CALL
but you can test other options like MediaRecorder.AudioSource.VOICE_COMMUNICATION
and also the microphone just to see if there are any hardware issues on your phone.
这篇关于通话录音 - 使其在 Nexus 5X 上工作(可以生根或自定义 ROM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!