This commit is contained in:
isp
2025-03-04 15:18:06 -05:00
parent 94196692c8
commit bb17c0651e
7 changed files with 28 additions and 16 deletions

View File

@@ -51,11 +51,13 @@ dependencies {
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation("org.tensorflow:tensorflow-lite:2.6.0")
// implementation("com.google.android.gms:play-services-tflite:20.0.0")
implementation("uk.me.berndporr:iirj:1.7")
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.litert)
// implementation(libs.litert)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)

View File

@@ -21,8 +21,8 @@ import java.security.NoSuchAlgorithmException;
@SuppressWarnings("ResultOfMethodCallIgnored")
public class Downloader {
static final String modelFILE = "model.tflite";
static final String metaModelFILE = "metaModel.tflite";
static final String modelFILE = "modelfx.tflite";
static final String metaModelFILE = "metaModelfx.tflite";
static final String modelURL = "https://raw.githubusercontent.com/woheller69/whoBIRD-TFlite/master/BirdNET_GLOBAL_6K_V2.4_Model_FP16.tflite";
static final String model32URL = "https://raw.githubusercontent.com/woheller69/whoBIRD-TFlite/master/BirdNET_GLOBAL_6K_V2.4_Model_FP32.tflite";
static final String metaModelURL = "https://raw.githubusercontent.com/woheller69/whoBIRD-TFlite/master/BirdNET_GLOBAL_6K_V2.4_MData_Model_FP16.tflite";
@@ -63,8 +63,6 @@ public class Downloader {
public static void downloadModels(final Activity activity) {
File modelFile = new File(activity.getDir("filesdir", Context.MODE_PRIVATE) + "/" + modelFILE);
Log.d("Heyy","Model file checking");
modelFile.delete();
if (!modelFile.exists()) {
Log.d("whoBIRD", "model file does not exist");
Thread thread = new Thread(() -> {
@@ -76,6 +74,7 @@ public class Downloader {
Log.d("whoBIRD", "Download model");
URLConnection ucon = url.openConnection();
Log.d("whoBIRD", "i am here");
ucon.setReadTimeout(5000);
ucon.setConnectTimeout(10000);
@@ -86,11 +85,12 @@ public class Downloader {
FileOutputStream outStream = new FileOutputStream(modelFile);
byte[] buff = new byte[5 * 1024];
int len;
while ((len = inStream.read(buff)) != -1) {
outStream.write(buff, 0, len);
}
outStream.flush();
outStream.close();
inStream.close();
@@ -117,10 +117,15 @@ public class Downloader {
} catch (NoSuchAlgorithmException | IOException i) {
activity.runOnUiThread(() -> Toast.makeText(activity, activity.getResources().getString(R.string.error_download), Toast.LENGTH_SHORT).show());
modelFile.delete();
Log.w("whoBIRD", activity.getResources().getString(R.string.error_download), i);
}
});
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
} else {
Log.d("whoBIRD","model exists");
activity.runOnUiThread(() -> {
@@ -181,6 +186,11 @@ public class Downloader {
}
});
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
} else {
Log.d("whoBIRD", "meta file exists");
activity.runOnUiThread(() -> {

View File

@@ -31,6 +31,7 @@ class MainActivity : AppCompatActivity() {
}
)
Downloader.downloadModels(this)
requestPermissions()
soundClassifier = SoundClassifier(this, SoundClassifier.Options())
Location.requestLocation(this, soundClassifier)

View File

@@ -45,9 +45,9 @@ class SoundClassifier(
/** Path of the converted .tflite file, relative to the assets/ directory. */
val assetFile: String = "assets.txt",
/** Path of the converted .tflite file, relative to the assets/ directory. */
val modelPath: String = "model.tflite",
val modelPath: String = "modelfx.tflite",
/** Path of the meta model .tflite file, relative to the assets/ directory. */
val metaModelPath: String = "metaModel.tflite",
val metaModelPath: String = "metaModelfx.tflite",
/** The required audio sample rate in Hz. */
val sampleRate: Int = 48000,
/** Multiplier for audio samples */