@@ -8,8 +8,8 @@ import 'package:google_speech/google_speech.dart';
8
8
import 'package:logging/logging.dart' ;
9
9
import 'package:share_plus/share_plus.dart' ;
10
10
import 'package:shared_preferences/shared_preferences.dart' ;
11
- import 'package:simple_frame_app/audio_data_response .dart' ;
12
- import 'package:simple_frame_app/tap_data_response .dart' ;
11
+ import 'package:simple_frame_app/rx/audio .dart' ;
12
+ import 'package:simple_frame_app/rx/tap .dart' ;
13
13
import 'package:simple_frame_app/tx/code.dart' ;
14
14
import 'package:simple_frame_app/tx/plain_text.dart' ;
15
15
import 'package:simple_frame_app/text_utils.dart' ;
@@ -34,8 +34,8 @@ class MainAppState extends State<MainApp> with SimpleFrameAppState {
34
34
hierarchicalLoggingEnabled = true ;
35
35
Logger .root.level = Level .INFO ;
36
36
Logger ('Bluetooth' ).level = Level .OFF ;
37
- Logger ('AudioDR ' ).level = Level .FINE ;
38
- Logger ('TapDR ' ).level = Level .FINE ;
37
+ Logger ('RxAudio ' ).level = Level .FINE ;
38
+ Logger ('RxTap ' ).level = Level .FINE ;
39
39
40
40
Logger .root.onRecord.listen ((record) {
41
41
debugPrint ('${record .level .name }: [${record .loggerName }] ${record .time }: ${record .message }' );
@@ -122,7 +122,7 @@ class MainAppState extends State<MainApp> with SimpleFrameAppState {
122
122
try {
123
123
// listen for double taps to start/stop transcribing
124
124
_tapSubs? .cancel ();
125
- _tapSubs = tapDataResponse ( frame! .dataResponse, const Duration (milliseconds : 300 ) )
125
+ _tapSubs = RxTap (). attach ( frame! .dataResponse)
126
126
.listen ((taps) async {
127
127
if (taps >= 2 ) {
128
128
if (! _streaming) {
@@ -200,8 +200,10 @@ class MainAppState extends State<MainApp> with SimpleFrameAppState {
200
200
await frame! .sendMessage (TxCode (msgCode: 0x30 , value: 1 ));
201
201
202
202
try {
203
+ // TODO put this object where I can call on it later to detach()
204
+ var rxAudio = RxAudio (streaming: true );
203
205
// the audio stream from Frame, which needs to be closed() to stop the streaming recognition
204
- _audioSampleStream = audioDataStreamResponse (frame! .dataResponse);
206
+ _audioSampleStream = rxAudio. attach (frame! .dataResponse);
205
207
206
208
String prevText = '' ;
207
209
@@ -238,7 +240,7 @@ class MainAppState extends State<MainApp> with SimpleFrameAppState {
238
240
// but concatenate to the same string in our case, so don't update Frame display)
239
241
if (currentText != prevText) { // TODO (&& Latin-only script?)
240
242
// Frame can display 6 lines of plain text, so work out the text wrapping
241
- List <String > wrappedText = TextUtils .wrapTextSplit (currentText, 640 , 4 );
243
+ List <String > wrappedText = TextUtils .wrapText (currentText, 640 , 4 );
242
244
243
245
// then send the bottom 6 lines joined with newlines as a single string
244
246
// (they get split and drawn on the Lua side)
@@ -298,6 +300,9 @@ class MainAppState extends State<MainApp> with SimpleFrameAppState {
298
300
Future <void > _stopRecognition () async {
299
301
// tell Frame to stop streaming audio
300
302
await frame! .sendMessage (TxCode (msgCode: 0x30 , value: 0 ));
303
+
304
+ // TODO we should also be able to send
305
+ // rxAudio.detach() to close the controller controlling our audio stream
301
306
}
302
307
303
308
void _scrollToBottom () {
0 commit comments