我正在尝试在 Android(AVD - Pixel 2,API 30)上使用 DeepSpeech Java API 运行 tflite 模型。我在创建 DeepSpeechModel 对象时遇到了问题。我不知道它可能是什么。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tV = findViewById(R.id.textView);
if (ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
}
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
}
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() + "/deepspeech-0.9.3-models.tflite";
File f = new File(path);
if (f.exists()) {
tV.setText("aaaaaaa");
}
else
tV.setText("bbbbbbb");
try {
m = new DeepSpeechModel(f.getPath());
} catch (Exception e) {
tV.setText(tV.getText() + e.toString());
}
}
我在下载目录中有我的模型(我之前从 DeepSpeech 的 GitHub 下载了它),并且我在模型的构造函数中传递了该文件的路径。结果我收到:
"E/tflite: Could not open '/storage/emulated/0/Download/deepspeech-0.9.3-models.tflite'"
这很奇怪,因为 f.exists() 返回 true。如您所见,我具有 WRITE/READ 权限(以及在 AndroidManifest.xml 中)