From 74dc07014c59c74540af081fd08366961492ffbd Mon Sep 17 00:00:00 2001 From: Jaimin Rana Date: Mon, 25 Sep 2023 14:50:35 +0530 Subject: [PATCH] =?UTF-8?q?feat:=E2=9C=A8Added=20support=20for=20changing?= =?UTF-8?q?=20the=20audio=20recording=20quality(#121).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/chatview.dart | 2 +- .../models/send_message_configuration.dart | 32 +++++++++++++++++++ lib/src/widgets/chatui_textfield.dart | 8 ++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/lib/chatview.dart b/lib/chatview.dart index 83528dda..693931e3 100644 --- a/lib/chatview.dart +++ b/lib/chatview.dart @@ -29,6 +29,6 @@ export 'src/values/enumaration.dart'; export 'src/controller/chat_controller.dart'; export 'src/values/typedefs.dart'; export 'package:audio_waveforms/audio_waveforms.dart' - show WaveStyle, PlayerWaveStyle; + show WaveStyle, PlayerWaveStyle,AndroidEncoder,IosEncoder,AndroidOutputFormat; export 'src/models/receipts_widget_config.dart'; export 'src/extensions/extensions.dart' show MessageTypes; diff --git a/lib/src/models/send_message_configuration.dart b/lib/src/models/send_message_configuration.dart index fe5b5e0e..fd7c70d1 100644 --- a/lib/src/models/send_message_configuration.dart +++ b/lib/src/models/send_message_configuration.dart @@ -211,6 +211,11 @@ class VoiceRecordingConfiguration { this.micIcon, this.recorderIconColor, this.stopIcon, + this.sampleRate, + this.bitRate, + this.androidEncoder, + this.iosEncoder, + this.androidOutputFormat, }); /// Applies styles to waveform. @@ -237,4 +242,31 @@ class VoiceRecordingConfiguration { /// Applies color to mic and stop icon. final Color? recorderIconColor; + + /// Below parameter are use for changing the audio recoding quality. + + ///The sample-rate for audio in samples per second. + /// Higher the sample-rate, more sample will generate per second, + /// but also larger the file size. + ///default value:44100 + final int? sampleRate; + + /// Bitrate is the amount of data per second that the codec uses to encode + /// the audio. + /// Higher the bitrate, the better the quality, but also larger + /// the file size. + /// default value: null (platform will decide) + final int? bitRate; + + /// Audio encoder to be used for recording for IOS + /// default value:IosEncoder.kAudioFormatMPEG4AAC + final IosEncoder? iosEncoder; + + /// Audio encoder to be used for recording for Android + /// default value:AndroidEncoder.aac + final AndroidEncoder? androidEncoder; + + /// Audio decoder to be used for recording output for Android + /// default value: AndroidOutputFormat.mpeg4 + final AndroidOutputFormat? androidOutputFormat; } diff --git a/lib/src/widgets/chatui_textfield.dart b/lib/src/widgets/chatui_textfield.dart index 83638c66..2c00fa26 100644 --- a/lib/src/widgets/chatui_textfield.dart +++ b/lib/src/widgets/chatui_textfield.dart @@ -286,7 +286,13 @@ class _ChatUITextFieldState extends State { "Voice messages are only supported with android and ios platform", ); if (!isRecording.value) { - await controller?.record(); + await controller?.record( + sampleRate: voiceRecordingConfig?.sampleRate, + bitRate: voiceRecordingConfig?.bitRate, + androidEncoder: voiceRecordingConfig?.androidEncoder, + iosEncoder: voiceRecordingConfig?.iosEncoder, + androidOutputFormat: voiceRecordingConfig?.androidOutputFormat, + ); isRecording.value = true; } else { final path = await controller?.stop();