Skip to content
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

Checking signal for mono / noisereduce on multichannel audio #32

Open
timsainb opened this issue Jan 20, 2020 · 1 comment
Open

Checking signal for mono / noisereduce on multichannel audio #32

timsainb opened this issue Jan 20, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@timsainb
Copy link
Owner

Several people have asked for noisereduce to work for multiple channels.

@timsainb timsainb added the enhancement New feature or request label Jan 20, 2020
@Sharrnah
Copy link

Just a stupid idea since i just stumbled over this issue.

But what if you do each channel seperately?

untested pseudo code:

import noisereduce as nr
import numpy as np

def _interleave(left, right):
    """Given two separate arrays, return a new interleaved array

    This function is useful for converting separate left/right audio
    streams into one stereo audio stream.  Input arrays and returned
    array are Numpy arrays.
    """
    return np.ravel(np.vstack((left, right)), order='F')

audio_chunk = None # your audio data
input_channels = 2 # for stereo audio
sample_rate = 16000 # your audio sample rate
audio_data_dtype = np.int16 # your audio data type

if isinstance(audio_chunk, bytes):
        audio_chunk = np.frombuffer(audio_chunk, dtype=audio_data_dtype)
# reshaped to (-1, input_channels)
audio_data = audio_chunk.reshape(-1, input_channels)

# Process the channels
clean_channels = []
for i in range(input_channels):
        channel_data = audio_data[:, i]
        # reduce noise on channel
        channel_data = nr.reduce_noise(y=channel_data, sr=sample_rate)
        clean_channels.append(channel_data)

# Combine the channels again
final_audio_data = _interleave(*clean_channels)
# Convert back to bytes
np.asarray(final_audio_data, dtype=audio_data_dtype).tobytes()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants