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
0 commit comments