import 'dart:io'; import 'dart:typed_data'; import 'package:path/path.dart' as p; import 'package:path_provider/path_provider.dart'; import 'package:record/record.dart'; mixin AudioRecorderMixin { Future recordFile(AudioRecorder recorder, RecordConfig config) async { final path = await _getPath(); await recorder.start(config, path: path); } Future recordStream(AudioRecorder recorder, RecordConfig config) async { final path = await _getPath(); final file = File(path); final stream = await recorder.startStream(config); stream.listen( (data) { // ignore: avoid_print print( recorder.convertBytesToInt16(Uint8List.fromList(data)), ); file.writeAsBytesSync(data, mode: FileMode.append); }, // ignore: avoid_print onDone: () { // ignore: avoid_print print('End of stream. File written to $path.'); }, ); } void downloadWebData(String path) {} Future _getPath() async { final dir = await getApplicationDocumentsDirectory(); return p.join( dir.path, 'audio_${DateTime.now().millisecondsSinceEpoch}.m4a', ); } }