I use a trained model for audio classification in a flutter app. I use the tflite_audio plugin: ^0.3.0, when I start audio recording the app closes. Works well with a google teachablemachine model. help me
thisi is my code:
class Classification extends StatefulWidget {
const Classification({super.key});
@override
State<Classification> createState() => _ClassificationState();
}
class _ClassificationState extends State<Classification> {
String _sound = "Clicca sul pulsante per avviare";
bool _recording = false;
Stream<Map<dynamic, dynamic>>? result;
@override
void initState() {
TfliteAudio.loadModel(
model: "assets/model.tflite",
label: "assets/labels.txt",
// for Google's Teachable Machine models
//inputType: 'rawAudio',
// for decodedWav models use
inputType: 'decodedWav',
numThreads: 1,
isAsset: true
);
super.initState();
}
void _recorder() {
String recognition = "";
if (!_recording) {
setState(() {
_recording = true;
});
result = TfliteAudio.startAudioRecognition(
// sampleRate: 44100, //google
// bufferSize: 22016,
sampleRate: 16000,
bufferSize: 2000,
);
result?.listen((event) {
recognition = event["recognitionResult"];
}).onDone(() {
setState(() {
_recording = false;
_sound = recognition.split(" ")[1];
});
});
}
}
void _stop() {
TfliteAudio.stopAudioRecognition();
setState(() => _recording = false);
}
the code of error in console is:
V/TfliteAudio( 4294): Recognition started.
W/System.err( 4294): io.reactivex.rxjava3.exceptions.OnErrorNotImplementedException: The exception was not handled due to missing onError handler in the subscribe() method call. Further reading: https://github.com/ReactiveX/RxJava/wiki/Error-Handling | java.lang.IllegalArgumentException: Invalid input Tensor index: 1
W/System.err( 4294): at io.reactivex.rxjava3.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:718)
W/System.err( 4294): at io.reactivex.rxjava3.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:715)
…
E/AndroidRuntime( 4294): … 10 more
I/Process ( 4294): Sending signal. PID: 4294 SIG: 9
Lost connection to device.
I tried with audio and image metadata, but it keeps crashing. If I use models trained by goggle it works.
Rao2_it is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.