timsainb / noisereduce

Noise reduction in python using spectral gating (speech, bioacoustics, audio, time-domain signals)
MIT License
1.47k stars 231 forks source link

Reduce noise in stereo #114

Closed olawalejuwonm closed 3 weeks ago

olawalejuwonm commented 1 month ago

Hi.

Thanks for the awesome project.

The output of the sound is in mono (one channel), can there be option to set this or default it to multiple channel?

nuniz commented 1 month ago

The input to noisereduce is a 2-dimensional matrix, so you can input stereo into the algorithm and obtain stereo output. However, the noise estimation is not shared between the channels.

olawalejuwonm commented 1 month ago

How do I achieve that programmatically?

On Thu, 10 Oct 2024, 22:31 Asaf Zorea, @.***> wrote:

The input to noisereduce is a 2-dimensional matrix, so you can input stereo into the algorithm. However, the noise estimation is not shared between the channels.

— Reply to this email directly, view it on GitHub https://github.com/timsainb/noisereduce/issues/114#issuecomment-2406073021, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMSQ2BELAB3I6JZHJXPK4Z3Z23W3DAVCNFSM6AAAAABOOB7U42VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBWGA3TGMBSGE . You are receiving this because you authored the thread.Message ID: @.***>

nuniz commented 1 month ago

Take a look at the last part (Multichannel noise) of the example notebook - https://github.com/timsainb/noisereduce/blob/master/notebooks/1.0-test-noise-reduction.ipynb

olawalejuwonm commented 1 month ago

Thanks for the tip!

But will the output audio file be stereo as well?

On Fri, Oct 11, 2024 at 9:13 AM Asaf Zorea @.***> wrote:

Take a look at the last part (Multichannel noise) of the example notebook -

https://github.com/timsainb/noisereduce/blob/master/notebooks/1.0-test-noise-reduction.ipynb

— Reply to this email directly, view it on GitHub https://github.com/timsainb/noisereduce/issues/114#issuecomment-2406857877, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMSQ2BGA7MXQ4NRJRW756JLZ26CDVAVCNFSM6AAAAABOOB7U42VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBWHA2TOOBXG4 . You are receiving this because you authored the thread.Message ID: @.***>

nuniz commented 1 month ago

Yes. The output shape should be identical to the input shape.

olawalejuwonm commented 1 month ago

Ok, thanks.

I noticed this in the codebase:

audio_clip_cafe_2_channel = np.vstack([audio_clip_cafe, audio_clip_cafe])

reduced_noise = nr.reduce_noise(y = audio_clip_cafe_2_channel, sr=rate, n_std_thresh_stationary=1.5,stationary=True)

Do I need to pass the audio to numpy first before using reduced_noise?

On Fri, Oct 11, 2024 at 1:23 PM Asaf Zorea @.***> wrote:

Yes. The output shape should be identical to the input shape.

— Reply to this email directly, view it on GitHub https://github.com/timsainb/noisereduce/issues/114#issuecomment-2407302970, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMSQ2BGUNCK2GDXN63KVOF3Z267MXAVCNFSM6AAAAABOOB7U42VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBXGMYDEOJXGA . You are receiving this because you authored the thread.Message ID: @.***>

nuniz commented 1 month ago

You can use either numpy or torch.

The simplest usage is:

import soundfile as sf
import noisereduce as nr

# READ AUDIO
data, sr= sf.read("<PATH_TO_AUDIO>")

# REDUCE NOISE
output = nr.reduce_noise(y = data, sr=sr)

# WRITE AUDIO
sf.write("<PATH_TO_AUDIO>", output , sr)
olawalejuwonm commented 1 month ago

What will be the value of

audio_clip_cafe_2_channel ?

On Fri, 11 Oct 2024, 19:33 Asaf Zorea, @.***> wrote:

You can use either numpy or torch.

The simplest usage is:

import soundfile as sf import noisereduce as nr

READ AUDIO

data, sr= sf.read("")

REDUCE NOISE

output = nr.reduce_noise(y = audio_clip_cafe_2_channel, sr=sr)

WRITE AUDIO

sf.write("", output , sr)

— Reply to this email directly, view it on GitHub https://github.com/timsainb/noisereduce/issues/114#issuecomment-2407935887, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMSQ2BATASWAKGRW7WJLMSLZ3AKWHAVCNFSM6AAAAABOOB7U42VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBXHEZTKOBYG4 . You are receiving this because you authored the thread.Message ID: @.***>

nuniz commented 1 month ago

The audio data

olawalejuwonm commented 1 month ago

I don't get.

Can you 🙏 please share the full code?

On Sat, 12 Oct 2024, 13:02 Asaf Zorea, @.***> wrote:

The audio data

— Reply to this email directly, view it on GitHub https://github.com/timsainb/noisereduce/issues/114#issuecomment-2408538592, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMSQ2BFTL52KBXM55J6M6UDZ3EFTRAVCNFSM6AAAAABOOB7U42VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBYGUZTQNJZGI . You are receiving this because you authored the thread.Message ID: @.***>

nuniz commented 1 month ago

You can use the code I've written to use noisereduce on stereo-data.

https://github.com/timsainb/noisereduce/issues/114#issuecomment-2407935887