@@ -22,9 +22,9 @@ import 'package:rhino/rhino_error.dart';
2222
2323class Rhino {
2424 static bool _resourcesExtracted = false ;
25- static String _defaultModelPath;
25+ static String ? _defaultModelPath;
2626
27- int _handle;
27+ int ? _handle;
2828 final String _contextInfo;
2929 final Pointer <Int16 > _cFrame;
3030
@@ -56,7 +56,7 @@ class Rhino {
5656 ///
5757 /// returns an instance of the speech-to-intent engine
5858 static Future <Rhino > create (String contextPath,
59- {String modelPath, double sensitivity = 0.5 }) async {
59+ {String ? modelPath, double sensitivity = 0.5 }) async {
6060 if (! _resourcesExtracted) {
6161 await _extractRhinoResources ();
6262 _resourcesExtracted = true ;
@@ -66,6 +66,9 @@ class Rhino {
6666 throw new PvArgumentError ("No context file provided." );
6767 }
6868
69+ if (modelPath == null && _defaultModelPath == null ) {
70+ throw new PvError ("No model file provided and default model file not available." );
71+ }
6972 modelPath ?? = _defaultModelPath;
7073
7174 if (sensitivity < 0 || sensitivity > 1 || sensitivity.isNaN) {
@@ -74,7 +77,7 @@ class Rhino {
7477 }
7578
7679 // generate arguments for ffi
77- Pointer <Utf8 > cModelPath = modelPath.toNativeUtf8 ();
80+ Pointer <Utf8 > cModelPath = modelPath! .toNativeUtf8 ();
7881 Pointer <Utf8 > cContextPath = contextPath.toNativeUtf8 ();
7982 Pointer <IntPtr > handlePtr = malloc <IntPtr >(1 );
8083
@@ -112,7 +115,7 @@ class Rhino {
112115 /// - isUnderstood: if isFinalized, whether Rhino understood what it heard based on the context
113116 /// - intent: if isUnderstood, name of intent that were inferred
114117 /// - slots: if isUnderstood, dictionary of slot keys and values that were inferred
115- Map <String , dynamic > process (List <int > frame) {
118+ Map <String , dynamic > process (List <int >? frame) {
116119 if (_handle == null ) {
117120 throw new PvStateError (
118121 "Attempted to process an audio frame after Rhino was been deleted." );
@@ -132,7 +135,7 @@ class Rhino {
132135 _cFrame.asTypedList (frame.length).setAll (0 , frame);
133136 Pointer <Uint8 > isFinalized = malloc (1 );
134137
135- int status = _rhinoProcess (_handle, _cFrame, isFinalized);
138+ int status = _rhinoProcess (_handle! , _cFrame, isFinalized);
136139 PvStatus pvStatus = PvStatus .values[status];
137140 if (pvStatus != PvStatus .SUCCESS ) {
138141 pvStatusToException (pvStatus, "Rhino failed to process an audio frame." );
@@ -147,7 +150,7 @@ class Rhino {
147150
148151 // get isUnderstood
149152 Pointer <Uint8 > isUnderstood = malloc (1 );
150- status = _rhinoIsUnderstood (_handle, isUnderstood);
153+ status = _rhinoIsUnderstood (_handle! , isUnderstood);
151154 pvStatus = PvStatus .values[status];
152155 if (pvStatus != PvStatus .SUCCESS ) {
153156 pvStatusToException (pvStatus, "Rhino failed to get IsUnderstood value." );
@@ -161,7 +164,7 @@ class Rhino {
161164 Pointer <Int32 > cNumSlots = malloc (1 );
162165 Pointer <Pointer <Pointer <Utf8 >>> cSlots = malloc (1 );
163166 Pointer <Pointer <Pointer <Utf8 >>> cValues = malloc (1 );
164- status = _rhinoGetIntent (_handle, cIntent, cNumSlots, cSlots, cValues);
167+ status = _rhinoGetIntent (_handle! , cIntent, cNumSlots, cSlots, cValues);
165168 pvStatus = PvStatus .values[status];
166169 if (pvStatus != PvStatus .SUCCESS ) {
167170 pvStatusToException (pvStatus, "Rhino failed to get intent." );
@@ -178,7 +181,7 @@ class Rhino {
178181 inference['slots' ] = slots;
179182
180183 // free slots
181- status = _rhinoFreeSlotsAndValues (_handle, cSlots[0 ], cValues[0 ]);
184+ status = _rhinoFreeSlotsAndValues (_handle! , cSlots[0 ], cValues[0 ]);
182185 pvStatus = PvStatus .values[status];
183186 if (pvStatus != PvStatus .SUCCESS ) {
184187 pvStatusToException (pvStatus, "Rhino failed to free slots." );
@@ -188,7 +191,7 @@ class Rhino {
188191 }
189192
190193 // reset Rhino
191- status = _rhinoReset (_handle);
194+ status = _rhinoReset (_handle! );
192195 pvStatus = PvStatus .values[status];
193196 if (pvStatus != PvStatus .SUCCESS ) {
194197 pvStatusToException (pvStatus, "Rhino failed to reset." );
@@ -200,7 +203,7 @@ class Rhino {
200203 /// Frees memory that was allocated for Rhino
201204 void delete () {
202205 if (_handle != null ) {
203- _rhinoDelete (_handle);
206+ _rhinoDelete (_handle! );
204207 _handle = null ;
205208 }
206209 }
0 commit comments