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

@@ -2,9 +2,12 @@
<project version="4"> <project version="4">
<component name="deploymentTargetSelector"> <component name="deploymentTargetSelector">
<selectionStates> <selectionStates>
<SelectionState runConfigName="mobile">
<option name="selectionMode" value="DROPDOWN" />
</SelectionState>
<SelectionState runConfigName="wear"> <SelectionState runConfigName="wear">
<option name="selectionMode" value="DROPDOWN" /> <option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2025-03-03T16:49:07.365262400Z"> <DropdownSelection timestamp="2025-03-03T17:08:48.726190400Z">
<Target type="DEFAULT_BOOT"> <Target type="DEFAULT_BOOT">
<handle> <handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=569cc5b0" /> <DeviceId pluginId="PhysicalDevice" identifier="serial=569cc5b0" />
@@ -13,9 +16,6 @@
</DropdownSelection> </DropdownSelection>
<DialogSelection /> <DialogSelection />
</SelectionState> </SelectionState>
<SelectionState runConfigName="mobile">
<option name="selectionMode" value="DROPDOWN" />
</SelectionState>
</selectionStates> </selectionStates>
</component> </component>
</project> </project>

1
.idea/misc.xml generated
View File

@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">

View File

@@ -21,7 +21,7 @@ media3Common = "1.4.0"
composeMaterial3 = "1.0.0-alpha23" composeMaterial3 = "1.0.0-alpha23"
workRuntimeKtx = "2.9.1" workRuntimeKtx = "2.9.1"
lifecycleRuntimeKtx = "2.6.1" lifecycleRuntimeKtx = "2.6.1"
litert = "1.0.1" #litert = "1.0.1"
[libraries] [libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@@ -51,7 +51,7 @@ androidx-compose-material3 = { group = "androidx.wear.compose", name = "compose-
androidx-work-runtime-ktx = { group = "androidx.work", name = "work-runtime-ktx", version.ref = "workRuntimeKtx" } androidx-work-runtime-ktx = { group = "androidx.work", name = "work-runtime-ktx", version.ref = "workRuntimeKtx" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" } androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" } androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
litert = { group = "com.google.ai.edge.litert", name = "litert", version.ref = "litert" } #litert = { group = "com.google.ai.edge.litert", name = "litert", version.ref = "litert" }
[plugins] [plugins]
android-application = { id = "com.android.application", version.ref = "agp" } android-application = { id = "com.android.application", version.ref = "agp" }

View File

@@ -51,11 +51,13 @@ dependencies {
implementation(libs.androidx.activity.compose) implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom)) implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui) 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("uk.me.berndporr:iirj:1.7")
implementation(libs.androidx.ui.graphics) implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview) implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3) implementation(libs.androidx.material3)
implementation(libs.litert) // implementation(libs.litert)
testImplementation(libs.junit) testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core) androidTestImplementation(libs.androidx.espresso.core)

View File

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

View File

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

View File

@@ -45,9 +45,9 @@ class SoundClassifier(
/** Path of the converted .tflite file, relative to the assets/ directory. */ /** Path of the converted .tflite file, relative to the assets/ directory. */
val assetFile: String = "assets.txt", val assetFile: String = "assets.txt",
/** Path of the converted .tflite file, relative to the assets/ directory. */ /** 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. */ /** 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. */ /** The required audio sample rate in Hz. */
val sampleRate: Int = 48000, val sampleRate: Int = 48000,
/** Multiplier for audio samples */ /** Multiplier for audio samples */