From fea9eab83fddaab95779453eb121fa00fd5bab09 Mon Sep 17 00:00:00 2001 From: dendenso Date: Sun, 26 Jul 2020 22:30:27 -0700 Subject: [PATCH 1/2] incomplete algorithm using sleep and the boolean while loop for continuously sending audio files. --- lib/components/recordingSession/recorder.dart | 17 +++++++++++++++++ lib/components/recordingSession/websocket.dart | 1 + 2 files changed, 18 insertions(+) diff --git a/lib/components/recordingSession/recorder.dart b/lib/components/recordingSession/recorder.dart index 1a8cc09..d36e7f7 100644 --- a/lib/components/recordingSession/recorder.dart +++ b/lib/components/recordingSession/recorder.dart @@ -31,6 +31,9 @@ class Recorder extends StatefulWidget { class _RecorderState extends State { bool _isRecording = false; + // added code + FlutterSoundHelper soundHelper = FlutterSoundHelper(); + //end code StreamSubscription _recorderSubscription; FlutterSoundRecorder recorderModule; String _recorderTxt = '00:00:00'; @@ -59,6 +62,7 @@ class _RecorderState extends State { ws = widget.ws; } +// audio session opened Future startAudioSession() async { recorderModule.openAudioSession( focus: AudioFocus.requestFocusTransient, @@ -67,6 +71,14 @@ class _RecorderState extends State { device: AudioDevice.speaker); } + Future getAudioData() async { + while (_isRecording) { + await recorderModule.startRecorder(); + sleep(const Duration(seconds: 10)); + await recorderModule.stopRecorder(); + } + } + Future cancelRecorderSubscriptions() async { if (_recorderSubscription != null) { _recorderSubscription.cancel(); @@ -110,6 +122,7 @@ class _RecorderState extends State { codec: _codec, bitRate: 16000, sampleRate: 16000, + numChannels: 2, audioSource: AudioSource.voice_communication, ); print('startRecorder'); @@ -123,6 +136,10 @@ class _RecorderState extends State { isUtc: true); final String formattedDate = DateFormat('mm:ss:SS', 'en_US').format(date); + // added code here + getAudioData(); //int return + // change e.duration for varying times. + // end of added code setState(() { _recorderTxt = formattedDate.substring(0, 8); _dbLevel = e.decibels; diff --git a/lib/components/recordingSession/websocket.dart b/lib/components/recordingSession/websocket.dart index 21ba075..865707a 100644 --- a/lib/components/recordingSession/websocket.dart +++ b/lib/components/recordingSession/websocket.dart @@ -20,6 +20,7 @@ class MyWebSocket { Future sendAudioFile( String exportedAudioData, int userID, String topic) async { final List audioData = await processAudioFile(exportedAudioData); + print(audioData.toString() + '\n'); // array of integers/bytes channel.sink.add( json.encode( {'audio_data': audioData, 'user_id': userID.toInt(), 'topic': topic}, From ddc36ef1800cf3a1b028c7c0471ed7e918f7f8f2 Mon Sep 17 00:00:00 2001 From: dendenso Date: Fri, 7 Aug 2020 17:18:31 -0700 Subject: [PATCH 2/2] removed unused int variable --- lib/components/recordingSession/recorder.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/components/recordingSession/recorder.dart b/lib/components/recordingSession/recorder.dart index c9e0fe7..b85ca02 100644 --- a/lib/components/recordingSession/recorder.dart +++ b/lib/components/recordingSession/recorder.dart @@ -46,7 +46,6 @@ class _RecorderState extends State { Directory tempDir; String savePath; int sessionCounter = 0; - int elapsedTime; Future initializeRecorder() async { tempDir = await getApplicationDocumentsDirectory();