1

I'am trying to run a tflite model with DeepSpeech Java API on the Android (AVD - Pixel 2, API 30). I have encountered a problem during creation of DeepSpeechModel object. I don't have any idea what it could be.

@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());
    }
}

I have my model in downloads directory (I downloaded it before from DeepSpeech's GitHub) and I'am passing path to that file in a model's constructor. In the result of that I'am receiving:

"E/tflite: Could not open '/storage/emulated/0/Download/deepspeech-0.9.3-models.tflite'"

It's strange because f.exists() returns true. As you see I have WRITE/READ permissions (as well in AndroidManifest.xml)

JD99
  • 11
  • 1
  • `tV.setText("bbbbbbb");` That is not very informative. Why not just tell that the directory does not exist? But worse: if the directory does not exist you continu trying to get a file in it. Do you think that would succeed? – blackapps Jun 05 '21 at 17:09
  • Also try f.canRead() before use. The same for the file. – blackapps Jun 05 '21 at 17:11

0 Answers0