我正在开发一个应用程序,其中我想要生成一个语音文件,即书面文本使用文本到语音每次去电。我能够检测到接收者何时使用可访问性服务应答呼叫。以下是代码:
public class CallDetection extends AccessibilityService {
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
Log.i("myaccess", "in window changed");
AccessibilityNodeInfo info = event.getSource();
if (info != null && info.getText() != null) {
String duration = info.getText().toString();
String zeroSeconds = String.format("%02d:%02d", new Object[]{Integer.valueOf(0), Integer.valueOf(0)});
String firstSecond = String.format("%02d:%02d", new Object[]{Integer.valueOf(0), Integer.valueOf(1)});
Log.d("myaccess", "after calculation - " + zeroSeconds + " --- " + firstSecond + " --- " + duration);
if (zeroSeconds.equals(duration) || firstSecond.equals(duration)) {
Toast.makeText(getApplicationContext(), "Call answered", Toast.LENGTH_SHORT).show();
// Your Code goes here
}
info.recycle();
}
}
}
@Override
protected void onServiceConnected() {
super.onServiceConnected();
Toast.makeText(this, "Service connected", Toast.LENGTH_SHORT).show();
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
info.notificationTimeout = 0;
info.packageNames = null;
setServiceInfo(info);
}
@Override
public void onInterrupt() {
}}
现在,我正在使用文本到语音来播放声音,但这在这里不起作用。我既不能在服务中使用它,也不能在其他电话上使用任何语音。我搜索了一下,发现android不允许应用程序在通话过程中发送语音。这是真的吗?帮我解决这个问题。
发布于 2018-05-26 01:28:59
你的发现是完全正确的。出于安全考虑,Android API不允许直接访问语音输入。因此,没有办法在普通设备上实现你想要做的事情。
我们脑海中浮现的另一种可能性是在call.See期间使用official docs中关于在通话期间使用媒体播放器的引述来播放音频剪辑
您只能将音频数据回放到标准输出设备。目前,这是移动设备扬声器或蓝牙耳机。您不能在呼叫过程中播放对话音频中的声音文件。
唯一的跳跃是自定义操作系统/硬件,它将提供的音频作为正常设备的麦克风输入。
https://stackoverflow.com/questions/50429134
复制相似问题