From cd1821f2b6ff64d0b9373881dc30b378b3d0f6c8 Mon Sep 17 00:00:00 2001 From: p42ity Date: Fri, 9 Feb 2024 16:50:19 +0000 Subject: [PATCH] Avoid truncated voice messages for affected devices There were some devices which are known to produce truncated voice messages from time to time. I investigated this issue on a Fairphone 4 and found a configuration which did not show this behaviour in my experiments. These devices are very sensitive on AAC settings. That's why I added an extra section for them. The list of devices can be adjusted. Reviewed-on: https://codeberg.org/iNPUTmice/Conversations/pulls/192 Co-authored-by: p42ity Co-committed-by: p42ity --- .../conversations/ui/RecordingActivity.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java b/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java index df3dabdce..5432ff335 100644 --- a/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java @@ -17,6 +17,8 @@ import android.widget.Toast; import androidx.databinding.DataBindingUtil; +import com.google.common.collect.ImmutableSet; + import java.io.File; import java.lang.ref.WeakReference; import java.text.SimpleDateFormat; @@ -25,6 +27,7 @@ import java.util.Locale; import java.util.Objects; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.Set; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; @@ -95,6 +98,16 @@ public class RecordingActivity extends Activity implements View.OnClickListener } } + private static final Set AAC_SENSITIVE_DEVICES = + new ImmutableSet.Builder() + .add("FP4") // Fairphone 4 https://codeberg.org/monocles/monocles_chat/issues/133 + .add("ONEPLUS A6000") // OnePlus 6 https://github.com/iNPUTmice/Conversations/issues/4329 + .add("ONEPLUS A6003") // OnePlus 6 https://github.com/iNPUTmice/Conversations/issues/4329 + .add("ONEPLUS A6010") // OnePlus 6T https://codeberg.org/monocles/monocles_chat/issues/133 + .add("ONEPLUS A6013") // OnePlus 6T https://codeberg.org/monocles/monocles_chat/issues/133 + .add("Pixel 4a") // Pixel 4a https://github.com/iNPUTmice/Conversations/issues/4223 + .build(); + private boolean startRecording() { mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); @@ -107,9 +120,16 @@ public class RecordingActivity extends Activity implements View.OnClickListener } else { outputFormat = MediaRecorder.OutputFormat.MPEG_4; mRecorder.setOutputFormat(outputFormat); - mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); - mRecorder.setAudioEncodingBitRate(96000); - mRecorder.setAudioSamplingRate(22050); + if (AAC_SENSITIVE_DEVICES.contains(Build.MODEL)) { + // Changing these three settings for AAC sensitive devices might lead to sporadically truncated (cut-off) voice messages. + mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.HE_AAC); + mRecorder.setAudioSamplingRate(24000); + mRecorder.setAudioEncodingBitRate(28000); + } else { + mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); + mRecorder.setAudioSamplingRate(22050); + mRecorder.setAudioEncodingBitRate(96000); + } } setupOutputFile(outputFormat); mRecorder.setOutputFile(mOutputFile.getAbsolutePath());