run method
This application uses platform speech-to-text to listen to audio from the host mic, convert to text, and send the text to the Frame. A Wiki query is also sent, and the resulting content is shown in Frame. The lifetime of this run() is short, it sets up the listeners for taps and speech but keeps application state as running. It has a running main loop on the Frame (frame_app.lua)
Implementation
@override
Future<void> run() async {
currentState = ApplicationState.running;
if (mounted) setState(() {});
// listen for taps for next(1)/prev(2) page and new query (3)
_tapSubs?.cancel();
_tapSubs = RxTap().attach(frame!.dataResponse).listen((taps) async {
_log.fine(() =>
'taps: $taps, currentPageBeforeTap: $_currentPage, extractLength: ${_extract?.length}');
switch (taps) {
case 1:
// next
if (_extract != null) {
if (nextPage()) {
await frame!.sendMessage(
TxPlainText(msgCode: 0x0a, text: getCurrentPageText()));
setState(() {});
}
}
break;
case 2:
// prev
if (_extract != null) {
if (previousPage()) {
await frame!.sendMessage(
TxPlainText(msgCode: 0x0a, text: getCurrentPageText()));
setState(() {});
}
}
break;
case 3:
// new query
_currentPage = -1;
setState(() {});
await _speechToText.listen(
listenOptions: SpeechListenOptions(
cancelOnError: true,
onDevice: true,
listenMode: ListenMode.search),
onResult: processSpeechRecognitionResult,
);
break;
default:
}
});
// let Frame know to subscribe for taps and send them to us
await frame!.sendMessage(TxCode(msgCode: 0x10, value: 1));
// prompt the user to begin tapping
await frame!.sendMessage(TxPlainText(
msgCode: 0x0a,
text:
'3-Tap for new query\n____\n1-Tap next page\n2-Tap previous page'));
}