Skip to content

Commit 92f5581

Browse files
committed
feat: add UI toggle for noise suppression
Signed-off-by: Maksim Sukharev <[email protected]>
1 parent 779d4a1 commit 92f5581

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/components/NewMessage/NewMessageAudioRecorder.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import IconClose from 'vue-material-design-icons/Close.vue'
5555
import IconMicrophoneOutline from 'vue-material-design-icons/MicrophoneOutline.vue'
5656
import { useAudioEncoder } from '../../composables/useAudioEncoder.ts'
5757
import { useGetToken } from '../../composables/useGetToken.ts'
58+
import { useSettingsStore } from '../../stores/settings.ts'
5859
import {
5960
destroyNoiseSuppressionWorklet,
6061
processNoiseSuppression,
@@ -82,6 +83,8 @@ export default {
8283
emits: ['recording', 'audioFile'],
8384
8485
setup() {
86+
const settingsStore = useSettingsStore()
87+
8588
const {
8689
isMediaRecorderReady,
8790
isMediaRecorderLoading,
@@ -90,6 +93,7 @@ export default {
9093
} = useAudioEncoder()
9194
9295
return {
96+
settingsStore,
9397
token: useGetToken(),
9498
isMediaRecorderReady,
9599
isMediaRecorderLoading,
@@ -179,7 +183,7 @@ export default {
179183
try {
180184
this.audioStream = await mediaDevicesManager.getUserMedia({
181185
audio: {
182-
noiseSuppression: false,
186+
noiseSuppression: !this.settingsStore.noiseSuppression,
183187
},
184188
video: false,
185189
})
@@ -197,7 +201,7 @@ export default {
197201
// Create a media recorder to capture the stream
198202
try {
199203
await registerNoiseSuppressionWorklet()
200-
const audioStreamProcessed = processNoiseSuppression(this.audioStream, true)
204+
const audioStreamProcessed = processNoiseSuppression(this.audioStream, this.settingsStore.noiseSuppression)
201205
this.mediaRecorder = new this.MediaRecorder(audioStreamProcessed, {
202206
mimeType: 'audio/wav',
203207
})

src/components/SettingsDialog/SettingsDialog.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
:label="t('spreed', 'Skip device preview before joining a call')"
3939
:description="t('spreed', 'Always shown if recording consent is required')"
4040
@update:model-value="setHideMediaSettings" />
41+
<NcFormBoxSwitch
42+
:model-value="settingsStore.noiseSuppression"
43+
:label="t('spreed', 'Enable noise suppression')"
44+
@update:model-value="toggleNoiseSuppression" />
4145
</NcFormBox>
4246

4347
<NcButton
@@ -401,6 +405,10 @@ export default {
401405
this.settingsStore.setShowMediaSettings(!newValue)
402406
},
403407
408+
toggleNoiseSuppression(newValue) {
409+
this.settingsStore.setNoiseSuppression(newValue)
410+
},
411+
404412
async setBlurVirtualBackgroundEnabled(value) {
405413
try {
406414
await this.settingsStore.setBlurVirtualBackgroundEnabled(value)

src/stores/settings.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const useSettingsStore = defineStore('settings', () => {
3030
const readStatusPrivacy = ref<PRIVACY_KEYS>(loadState('spreed', 'read_status_privacy', PRIVACY.PRIVATE))
3131
const typingStatusPrivacy = ref<PRIVACY_KEYS>(loadState('spreed', 'typing_privacy', PRIVACY.PRIVATE))
3232
const showMediaSettings = ref<boolean>(BrowserStorage.getItem('showMediaSettings') !== 'false')
33+
const noiseSuppression = ref<boolean>(BrowserStorage.getItem('noiseSuppression') !== 'false')
3334
const startWithoutMedia = ref<boolean | undefined>(getTalkConfig('local', 'call', 'start-without-media'))
3435
const blurVirtualBackgroundEnabled = ref<boolean | undefined>(getTalkConfig('local', 'call', 'blur-virtual-background'))
3536
const conversationsListStyle = ref<LIST_STYLE_OPTIONS | undefined>(getTalkConfig('local', 'conversations', 'list-style'))
@@ -68,6 +69,16 @@ export const useSettingsStore = defineStore('settings', () => {
6869
showMediaSettings.value = value
6970
}
7071

72+
/**
73+
* Update the noise suppression settings for the user
74+
*
75+
* @param value - new selected state
76+
*/
77+
function setNoiseSuppression(value: boolean) {
78+
BrowserStorage.setItem('noiseSuppression', value.toString())
79+
noiseSuppression.value = value
80+
}
81+
7182
/**
7283
* Update the blur virtual background setting for the user
7384
*
@@ -122,6 +133,7 @@ export const useSettingsStore = defineStore('settings', () => {
122133
readStatusPrivacy,
123134
typingStatusPrivacy,
124135
showMediaSettings,
136+
noiseSuppression,
125137
startWithoutMedia,
126138
blurVirtualBackgroundEnabled,
127139
conversationsListStyle,
@@ -132,6 +144,7 @@ export const useSettingsStore = defineStore('settings', () => {
132144
updateReadStatusPrivacy,
133145
updateTypingStatusPrivacy,
134146
setShowMediaSettings,
147+
setNoiseSuppression,
135148
setBlurVirtualBackgroundEnabled,
136149
updateStartWithoutMedia,
137150
updateConversationsListStyle,

0 commit comments

Comments
 (0)