8000 Add Noise Suppression (#1264) by ChabanovX · Pull Request #1287 · team113/messenger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add Noise Suppression (#1264) #1287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open

Conversation

ChabanovX
Copy link
Contributor
@ChabanovX ChabanovX commented Jun 20, 2025

Resolves #1264

Synopsis

Add user-configurable noise suppression now that medea_flutter_webrtc 0.14.0
exposes the feature (Desktop). Users need to toggle it in My Profile ▸ Media.

Solution

Upgrade deps. Extend MediaSettings. Migrate DB. Add API in repository. Paint UI. Write tests

Checklist

  • Created PR:
    • In draft mode
    • Name contains issue reference
    • Has type and k:: labels applied
  • Before review:
    • Documentation is updated (if required)
    • Tests are updated (if required)
    • Changes conform code style
    • CHANGELOG entry is added (if required)
    • FCM (final commit message) is posted or updated
    • Draft mode is removed
  • Review is completed and changes are approved
    • FCM (final commit message) is approved
  • Before merge:
    • Milestone is set
    • PR's name and description are correct and up-to-date
    • All temporary labels are removed

@ChabanovX ChabanovX added this to the 0.6.0 milestone Jun 20, 2025
@ChabanovX ChabanovX self-assigned this Jun 20, 2025
@ChabanovX ChabanovX added enhancement Improvement of existing features or bugfix k::UI/UX UI (user interface) and UX (user experience) changes k::refactor Refactor changes of existing code labels Jun 20, 2025
@ChabanovX ChabanovX force-pushed the 1264-add-noise-suppression branch from d70fb99 to dde9297 Compare June 24, 2025 10:16
Comment on lines 2169 to 2171
await track.getTrack().setNoiseSuppressionEnabled(
_noiseSuppressionEnabled!,
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChabanovX, I've noticed that CI fails to build Web platform due to NoiseSuppressionLevel enum not being available there. And that seems to be true, if we talk about NoiseSuppressionLevel from the medea_flutter_webrtc. I've discussed this matter with guys from medea_flutter_webrtc and they told me that we shouldn't use this enum from that package - instead the NoiseSuppressionLevel from medea_jason should be used. Can you please try that?

And in that case the proper method to change the noise suppression settings would be to call this method over track directly:

Suggested change
await track.getTrack().setNoiseSuppressionEnabled(
_noiseSuppressionEnabled!,
);
await track.setNoiseSuppressionEnabled(
_noiseSuppressionEnabled!,
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, got it!

@ChabanovX ChabanovX force-pushed the 1264-add-noise-suppression branch from 1610adf to 05968e1 Compare June 26, 2025 13:58
@ChabanovX ChabanovX force-pushed the 1264-add-noise-suppression branch from dc4ec3a to 5a0c024 Compare June 27, 2025 10:51
@ChabanovX ChabanovX changed the title Draft: Add Noise Suppression (#1264) Add Noise Suppression (#1264) Jun 27, 2025
@ChabanovX
Copy link
Contributor Author
ChabanovX commented Jun 27, 2025

FCM

Add noise suppression settings to MyProfile page (#1287, #1264)

@ChabanovX ChabanovX requested a review from SleepySquash June 27, 2025 11:30
Comment on lines 773 to 780
label_media_settings = Media settings
label_voice_processing = Voice processing
label_noise_suppression = Noise suppression
label_low = Low
label_medium = Moderate
label_high = High
label_very_high = Very high
label_message = Message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please sort these l10n keys alphabetically? You may install a sort extension to your IDE so that it can be easier.

Comment on lines 23 to 25
import 'package:medea_flutter_webrtc/medea_flutter_webrtc.dart' as webrtc;
import 'package:medea_flutter_webrtc/medea_flutter_webrtc.dart'
as webrtc
hide NoiseSuppressionLevel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this import is prefixed with webrtc, then Dart shouldn't confuse webrtc.NoiseSuppressionLevel from medea_flutter_webrtc with NoiseSuppressionLevel from medea_jason, since the first one requires a prefix to be specified. Thus this hide NoiseSuppressionLevel may be removed? Or not?

Copy link
Contributor Author
@ChabanovX ChabanovX Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it might be removed, but if we leave it as it is, then other developers might be hinted, that webrtc version of NoiseSuppressionLevel should be avoided. Might not be important though. Should I remove it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChabanovX, this approach seems to be true for every enum present both in medea_jason and medea_flutter_webrtc. Not sure that we will be able to address all of those in such way with hide.

@@ -2154,7 +2164,56 @@ class OngoingCall {
devices.firstWhereOrNull(
(e) => e.deviceId() == track.getTrack().deviceId(),
);

_addNoiseSuppression(track);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we await this call? Or shouldn't we?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think - yes, there is no reason for not awaiting this call

Comment on lines 75 to 101
/// Simulate [ProfileController].
class _NoiseController extends GetxController {
final media = Rx(MediaSettings(noiseSuppressionEnabled: false));

void setNoiseSuppressionEnabled(bool enabled) {
media.update((m) {
m ??= MediaSettings();
m.noiseSuppressionEnabled = enabled;
});
}

void setNoiseSuppressionLevelValue(NoiseSuppressionLevel level) {
media.update((m) {
m ??= MediaSettings();
m.noiseSuppressionLevel = level;
});
}
}

class _NoiseSuppressionView extends StatelessWidget {
const _NoiseSuppressionView(this.c);

final _NoiseController c;

@override
Widget build(BuildContext context) {
final style = Theme.of(context).style;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this test only tests the widgets defined and implemented in the test itself and not the application. Developers may forget the fact that whenever MyProfile pages is changed this code should be changed as well. It's easy to lose track of. Can't be just test the MyProfile page itself?

CHANGELOG.md Outdated
Comment on lines 31 to 36
[#1263]: /../../issue/1263
[#1264]: /../../issue/1264
[#1268]: /../../issue/1268
[#1280]: /../../pull/1280
[#1285]: /../../pull/1285
[#1285]: /../../pull/1287
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see the links being added, but no actual change entry?

Comment on lines 128 to 130
child: ClipPath(
clipper: _BottomEdgeClipper(),
child: AnimatedSize(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this clipping applied to every single Block affect performance? https://docs.flutter.dev/release/breaking-changes/clip-behavior#summary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, very good notice, I will add optional parameter for applying the clipping

class _BottomEdgeClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
const double kBig = 1e6;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@override
Path getClip(Size size) {
const double kBig = 1e6;
return Path()..addRect(Rect.fromLTRB(-kBig, 0, kBig, size.height));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use double.maxFinite here in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been debugging and noticed a problem using infinite values. I checked how rect is added to path and noticed this check:

bool _rectIsValid(Rect rect) {
  assert(!rect.hasNaN, 'Rect argument contained a NaN value.');
  return true;
}

double.infinity converts to NotANumber value and assertion happens. Hence, we cannot deal with infinite values and should leave finite number

10000

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChabanovX, why would you use a double.infinity then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, read as infinity, maxFinite is working just fine and should be used here

@ChabanovX ChabanovX force-pushed the 1264-add-noise-suppression branch from aa02b35 to 806543e Compare June 30, 2025 14:32
@SleepySquash SleepySquash modified the milestones: 0.5.2, 0.6.0 Jul 1, 2025
@ChabanovX ChabanovX force-pushed the 1264-add-noise-suppression branch from 4d20d13 to 806543e Compare July 1, 2025 13:39
@ChabanovX
Copy link
Contributor Author

Should we remove widget test since we in the future we are going to introduce e2e test?
Also, I cut commits related to e2e enhancing @SleepySquash

@SleepySquash
Copy link
Contributor

@ChabanovX,

Should we remove widget test since we in the future we are going to introduce e2e test?

Ok, let's remove it

@ChabanovX ChabanovX requested a review from SleepySquash July 2, 2025 08:46
Copy link
Contributor
@SleepySquash SleepySquash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChabanovX, be sure to read thoughtfully your code before sending it for a review, please.

Comment on lines -993 to +997
label_user_removed_user3 = {" "}{$user}
label_user_removed_user3 = { " "}{$user}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be fixed, I will never trust AI again to do the sorting and will write my own script to do it. So far I did not find a sorting extension, that would manage file with multicolumn labels.

F438
@@ -1048,4 +1054,4 @@ question_mark = ?
space = {" "}
space_or_space = {" "}or{" "}
space_plus_space = {" "}+{" "}
space_vertical_space = {" "}|{" "}
space_vertical_space = {" "}|{" "}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has no newline character at the end despite .editorconfig specified to have one:

[*]
...
end_of_line = lf
...

You should install an extension that would respect .editorconfig files and apply the settings specified in there.

Comment on lines 801 to 805
label_no_limit = ∞
label_no_messages = No messages
label_noise_suppression = Noise suppression
label_no_updates_are_available_subtitle = You have the latest version installed.
label_no_updates_are_available_title = No updates are available
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem sorted. #1287 (comment)
Why did you place this label between two label_no_* labels? What is the reasoning behind this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a poor sorting algorithm and will be fixed.

Comment on lines +2185 to +2198
// Currently works only on Desktop
if (PlatformUtils.isWeb || !PlatformUtils.isDesktop) {
Log.debug(
'❌ Noise suppression is not supported on this platform',
'$runtimeType',
);
return;
}

final enabled = _noiseSuppressionEnabled;
if (enabled == null) {
Log.debug('❌ _noiseSuppressionEnabled is null', '$runtimeType');
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think any logs should be printed if noise suppression is disabled or are unavailable for the current platform.

Comment on lines +2177 to +2183
10000
if (!track.isAudioProcessingAvailable()) {
Log.debug(
'❌ Audio processing not available for this track $track',
'$runtimeType',
);
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should be checked only if noise suppression is enabled and the current platform is supported. Otherwise I don't see any reason to check it.


final level = _noiseSuppressionLevel;
if (level == null) {
Log.debug('❌ _noiseSuppressionLevel is null', '$runtimeType');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This emoji makes it look like an error. Is it an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not an error, should be removed.

Log.debug('✅ set level to $level', '$runtimeType');
await track.setNoiseSuppressionLevel(level);
} catch (e, _) {
Log.error('💥 Failed to configure noise suppression: $e', '$runtimeType');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log should contain the track that failed to set the suppression for.

Comment on lines +86 to +88
/// Whether to clip overflowing content in height, but not width.
/// Defaults to `false` to avoid extra GPU work.
final bool clipHeight;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once again I carefully read the following paragraph; will be fixed.

LineDivider('label_voice_processing'.l10n),
const SizedBox(height: 16),
Obx(() {
// False by default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +839 to +840
// Values of NoiseSuppressionLevel
final values = NoiseSuppressionLevel.values;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments should cover only parts that aren't obvious, I suppose. Otherwise those can make code less readable despite its purpose to make it more readable. Don't you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, will be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features or bugfix k::refactor Refactor changes of existing code k::UI/UX UI (user interface) and UX (user experience) changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add noise suppression settings to MyProfile page
2 participants
0