Skip to content

Commit 8466485

Browse files
committed
init
1 parent 756e026 commit 8466485

File tree

17 files changed

+194
-16
lines changed

17 files changed

+194
-16
lines changed

.github/workflows/android-browserstack.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,21 @@ jobs:
4242
java-version: '11'
4343
distribution: 'temurin'
4444

45+
############## REMOVE AFTER RELEASE ##########################
46+
- name: Build binding
47+
run: ./gradlew assembleRelease --info
48+
working-directory: binding/android/Eagle
49+
############## REMOVE AFTER RELEASE ##########################
50+
4551
- name: Copy test_resources
4652
run: ./copy_test_resources.sh
4753

4854
- name: Inject AccessKey
4955
run: echo pvTestingAccessKey="${{secrets.PV_VALID_ACCESS_KEY}}" >> local.properties
5056

57+
- name: Inject Device
58+
run: echo pvTestingDevice="cpu:1" >> local.properties
59+
5160
- name: Inject Android keystore variables
5261
run: |
5362
echo storePassword="${{secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD}}" >> local.properties
@@ -94,12 +103,21 @@ jobs:
94103
java-version: '11'
95104
distribution: 'temurin'
96105

106+
############## REMOVE AFTER RELEASE ##########################
107+
- name: Build binding
108+
run: ./gradlew assembleRelease --info
109+
working-directory: binding/android/Eagle
110+
############## REMOVE AFTER RELEASE ##########################
111+
97112
- name: Copy test_resources
98113
run: ./copy_test_resources.sh
99114

100115
- name: Inject AccessKey
101116
run: echo pvTestingAccessKey="${{secrets.PV_VALID_ACCESS_KEY}}" >> local.properties
102117

118+
- name: Inject Device
119+
run: echo pvTestingDevice="cpu:1" >> local.properties
120+
103121
- name: Inject Android keystore variables
104122
run: |
105123
echo storePassword="${{secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD}}" >> local.properties

.github/workflows/android-demos.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,19 @@ jobs:
3838

3939
steps:
4040
- uses: actions/checkout@v3
41-
41+
42+
############## REMOVE AFTER RELEASE ##########################
43+
- name: Set up Java 11
44+
uses: actions/setup-java@v3
45+
with:
46+
java-version: 11
47+
distribution: 'temurin'
48+
49+
- name: Build binding
50+
run: ./gradlew assembleRelease --info
51+
working-directory: binding/android/Eagle
52+
############## REMOVE AFTER RELEASE ##########################
53+
4254
- name: Override gradle settings
4355
run: sed -i "s/com.android.tools.build:gradle:[0-9]*\.[0-9]*\.[0-9]*/com.android.tools.build:gradle:${{ matrix.agp-version }}/g" build.gradle
4456

.github/workflows/android-perf.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,21 @@ jobs:
5050
java-version: '11'
5151
distribution: 'temurin'
5252

53+
############## REMOVE AFTER RELEASE ##########################
54+
- name: Build binding
55+
run: ./gradlew assembleRelease --info
56+
working-directory: binding/android/Eagle
57+
############## REMOVE AFTER RELEASE ##########################
58+
5359
- name: Copy test_resources
5460
run: ./copy_test_resources.sh
5561

5662
- name: Inject AccessKey
5763
run: echo pvTestingAccessKey="${{secrets.PV_VALID_ACCESS_KEY}}" >> local.properties
5864

65+
- name: Inject Device
66+
run: echo pvTestingDevice="cpu:1" >> local.properties
67+
5968
- name: Inject Android keystore variables
6069
run: |
6170
echo storePassword="${{secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD}}" >> local.properties

.github/workflows/android-upload.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ jobs:
2323
steps:
2424
- uses: actions/checkout@v3
2525

26+
############## REMOVE AFTER RELEASE ##########################
27+
- name: set up JDK 11
28+
uses: actions/setup-java@v3
29+
with:
30+
java-version: 11
31+
distribution: 'temurin'
32+
33+
- name: Build binding
34+
run: ./gradlew assembleRelease --info
35+
working-directory: binding/android/Eagle
36+
############## REMOVE AFTER RELEASE ##########################
37+
2638
- name: set up JDK 17
2739
uses: actions/setup-java@v3
2840
with:

binding/android/Eagle/eagle/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
22

33
ext {
44
PUBLISH_GROUP_ID = 'ai.picovoice'
5-
PUBLISH_VERSION = '1.0.1'
5+
PUBLISH_VERSION = '2.0.0'
66
PUBLISH_ARTIFACT_ID = 'eagle-android'
77
}
88

binding/android/Eagle/eagle/src/main/java/ai/picovoice/eagle/Eagle.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 Picovoice Inc.
2+
Copyright 2023-2025 Picovoice Inc.
33
44
You may not use this file except in compliance with the license. A copy of the license is
55
located in the "LICENSE" file accompanying this source.
@@ -41,17 +41,34 @@ public static void setSdk(String sdk) {
4141
Eagle._sdk = sdk;
4242
}
4343

44+
/**
45+
* Lists all available devices that Eagle can use for inference.
46+
* Each entry in the list can be used as the `device` argument when initializing Eagle.
47+
*
48+
* @return Array of all available devices that Eagle can be used for inference.
49+
* @throws EagleException if getting available devices fails.
50+
*/
51+
public static String[] getAvailableDevices() throws EagleException {
52+
return EagleNative.listHardwareDevices();
53+
}
54+
4455
/**
4556
* Constructor.
4657
*
4758
* @param accessKey AccessKey obtained from Picovoice Console
4859
* @param modelPath Absolute path to the file containing Eagle model parameters.
60+
* @param device String representation of the device (e.g., CPU or GPU) to use for inference. If set to `best`, the most
61+
* suitable device is selected automatically. If set to `gpu`, the engine uses the first available GPU device.
62+
* To select a specific GPU device, set this argument to `gpu:${GPU_INDEX}`, where `${GPU_INDEX}` is the index of the
63+
* target GPU. If set to `cpu`, the engine will run on the CPU with the default number of threads. To specify the
64+
* number of threads, set this argument to `cpu:${NUM_THREADS}`, where `${NUM_THREADS}` is the desired number of threads.
4965
* @param speakerProfiles A list of EagleProfile objects. This can be constructed using `EagleProfiler`.
5066
* @throws EagleException if there is an error while initializing Eagle.
5167
*/
5268
private Eagle(
5369
String accessKey,
5470
String modelPath,
71+
String device,
5572
EagleProfile[] speakerProfiles) throws EagleException {
5673
long[] profileHandles = new long[speakerProfiles.length];
5774

@@ -63,6 +80,7 @@ private Eagle(
6380
handle = EagleNative.init(
6481
accessKey,
6582
modelPath,
83+
device,
6684
speakerProfiles.length,
6785
profileHandles);
6886

@@ -152,6 +170,7 @@ public static class Builder {
152170

153171
private String accessKey = null;
154172
private String modelPath = null;
173+
private String device = null;
155174

156175
private EagleProfile[] speakerProfiles = null;
157176

@@ -165,6 +184,11 @@ public Builder setModelPath(String modelPath) {
165184
return this;
166185
}
167186

187+
public Builder setDevice(String device) {
188+
this.device = device;
189+
return this;
190+
}
191+
168192
public Builder setSpeakerProfiles(EagleProfile[] speakerProfiles) {
169193
this.speakerProfiles = speakerProfiles;
170194
return this;
@@ -213,7 +237,7 @@ private static String extractResource(
213237
* @throws EagleException if there is an error while initializing Eagle.
214238
*/
215239
public Eagle build(Context context) throws EagleException {
216-
if (accessKey == null || this.accessKey.equals("")) {
240+
if (accessKey == null || accessKey.equals("")) {
217241
throw new EagleInvalidArgumentException("No AccessKey was provided to Eagle");
218242
}
219243

@@ -236,11 +260,15 @@ public Eagle build(Context context) throws EagleException {
236260
}
237261
}
238262

239-
if (speakerProfiles == null || this.speakerProfiles.length == 0) {
263+
if (device == null) {
264+
device = "best";
265+
}
266+
267+
if (speakerProfiles == null || speakerProfiles.length == 0) {
240268
throw new EagleInvalidArgumentException("No speaker profiles provided to Eagle");
241269
}
242270

243-
return new Eagle(accessKey, modelPath, speakerProfiles);
271+
return new Eagle(accessKey, modelPath, device, speakerProfiles);
244272
}
245273
}
246274

binding/android/Eagle/eagle/src/main/java/ai/picovoice/eagle/EagleNative.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 Picovoice Inc.
2+
Copyright 2023-2025 Picovoice Inc.
33
44
You may not use this file except in compliance with the license. A copy of the license is
55
located in the "LICENSE" file accompanying this source.
@@ -27,6 +27,7 @@ class EagleNative {
2727
static native long init(
2828
String accessKey,
2929
String modelPath,
30+
String device,
3031
int numSpeakers,
3132
long[] speakerProfiles) throws EagleException;
3233

@@ -36,4 +37,6 @@ static native long init(
3637

3738
static native void reset(long object) throws EagleException;
3839

40+
static native String[] listHardwareDevices() throws EagleException;
41+
3942
}

binding/android/Eagle/eagle/src/main/java/ai/picovoice/eagle/EagleProfiler.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 Picovoice Inc.
2+
Copyright 2023-2025 Picovoice Inc.
33
44
You may not use this file except in compliance with the license. A copy of the license is
55
located in the "LICENSE" file accompanying this source.
@@ -43,16 +43,38 @@ public static void setSdk(String sdk) {
4343
EagleProfiler._sdk = sdk;
4444
}
4545

46+
/**
47+
* Lists all available devices that Eagle can use for inference.
48+
* Each entry in the list can be used as the `device` argument when initializing Eagle.
49+
*
50+
* @return Array of all available devices that Eagle can be used for inference.
51+
* @throws EagleException if getting available devices fails.
52+
*/
53+
public static String[] getAvailableDevices() throws EagleException {
54+
return EagleNative.listHardwareDevices();
55+
}
56+
4657
/**
4758
* Constructor.
4859
*
4960
* @param accessKey AccessKey obtained from Picovoice Console
5061
* @param modelPath Absolute path to the file containing Eagle model parameters.
62+
* @param device String representation of the device (e.g., CPU or GPU) to use for inference. If set to `best`, the most
63+
* suitable device is selected automatically. If set to `gpu`, the engine uses the first available GPU device.
64+
* To select a specific GPU device, set this argument to `gpu:${GPU_INDEX}`, where `${GPU_INDEX}` is the index of the
65+
* target GPU. If set to `cpu`, the engine will run on the CPU with the default number of threads. To specify the
66+
* number of threads, set this argument to `cpu:${NUM_THREADS}`, where `${NUM_THREADS}` is the desired number of threads.
5167
* @throws EagleException if there is an error while initializing EagleProfiler.
5268
*/
53-
private EagleProfiler(String accessKey, String modelPath) throws EagleException {
69+
private EagleProfiler(
70+
String accessKey,
71+
String modelPath,
72+
String device) throws EagleException {
5473
EagleNative.setSdk(EagleProfiler._sdk);
55-
handle = EagleProfilerNative.init(accessKey, modelPath);
74+
handle = EagleProfilerNative.init(
75+
accessKey,
76+
modelPath,
77+
device);
5678
minEnrollSamples = EagleProfilerNative.minEnrollSamples(handle);
5779
}
5880

@@ -148,6 +170,7 @@ public static class Builder {
148170

149171
private String accessKey = null;
150172
private String modelPath = null;
173+
private String device = null;
151174

152175
public Builder setAccessKey(String accessKey) {
153176
this.accessKey = accessKey;
@@ -159,6 +182,11 @@ public Builder setModelPath(String modelPath) {
159182
return this;
160183
}
161184

185+
public Builder setDevice(String device) {
186+
this.device = device;
187+
return this;
188+
}
189+
162190
private static void extractPackageResources(Context context) throws EagleIOException {
163191
final Resources resources = context.getResources();
164192

@@ -220,7 +248,11 @@ public EagleProfiler build(Context context) throws EagleException {
220248
}
221249
}
222250

223-
return new EagleProfiler(accessKey, modelPath);
251+
if (device == null) {
252+
device = "best";
253+
}
254+
255+
return new EagleProfiler(accessKey, modelPath, device);
224256
}
225257
}
226258

binding/android/EagleTestApp/eagle-test-app/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ if (rootProject.file("local.properties").exists()) {
77
if (project.hasProperty("pvTestingAccessKey")) {
88
properties.put("pvTestingAccessKey", project.getProperty("pvTestingAccessKey"))
99
}
10+
if (project.hasProperty("pvTestingDevice")) {
11+
properties.put("pvTestingDevice", project.getProperty("pvTestingDevice"))
12+
}
1013
if (project.hasProperty("numTestIterations")) {
1114
properties.put("numTestIterations", project.getProperty("numTestIterations"))
1215
}
@@ -44,6 +47,7 @@ android {
4447
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
4548

4649
resValue 'string', 'pvTestingAccessKey', properties.getProperty("pvTestingAccessKey", "")
50+
resValue 'string', 'pvTestingDevice', properties.getProperty("pvTestingDevice", "")
4751
resValue 'string', 'numTestIterations', properties.getProperty("numTestIterations", "")
4852
resValue 'string', 'enrollPerformanceThresholdSec', properties.getProperty("enrollPerformanceThresholdSec", "")
4953
resValue 'string', 'procPerformanceThresholdSec', properties.getProperty("procPerformanceThresholdSec", "")
@@ -116,7 +120,7 @@ dependencies {
116120
implementation 'androidx.appcompat:appcompat:1.6.1'
117121
implementation 'com.google.android.material:material:1.8.0'
118122
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
119-
implementation 'ai.picovoice:eagle-android:1.0.1'
123+
implementation files('../../Eagle/eagle/build/outputs/aar/eagle-release.aar')
120124

121125
// Espresso UI Testing
122126
androidTestImplementation 'androidx.test.ext:junit:1.1.5'

binding/android/EagleTestApp/eagle-test-app/src/androidTest/java/ai/picovoice/eagle/testapp/BaseTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 Picovoice Inc.
2+
Copyright 2023-2025 Picovoice Inc.
33
44
You may not use this file except in compliance with the license. A copy of the license is
55
located in the "LICENSE" file accompanying this source.
@@ -60,6 +60,7 @@ public void Setup() throws IOException {
6060
defaultModelPath = getModelFilepath("eagle_params.pv");
6161

6262
accessKey = appContext.getString(R.string.pvTestingAccessKey);
63+
device = appContext.getString(R.string.pvTestingDevice);
6364
}
6465

6566
protected static short[] readAudioFile(String audioFile) throws Exception {

0 commit comments

Comments
 (0)