Ejemplo n.º 1
0
def matching_filenames(list1, list_of_lists):
    list1_files = []
    if isinstance(list1[0], tuple):
        for item in list1:
            if len(item) != 2:
                # ensures expected length of 2: (encoded_label, pathway)
                raise ValueError('Expected a list of tuple pairs: encoded '+\
                    'label and associated pathway. Received tuple of length ', len(item))
            # checks to ensure encoded label comes first
            if isinstance(
                    item[0],
                    int) or isinstance(item[0], str) and item[0].isdigit():
                list1_files.append(item[1])
    elif isinstance(list1[0], str) or isinstance(
            list1[0], pathlib.PosixPath) or isinstance(list1[0],
                                                       pathlib.PurePath):
        list1_files = list1
    other_lists_files = []
    for l in list_of_lists:
        if isinstance(l[0], tuple):
            for item in l:
                if len(item) != 2:
                    # ensures expected length of 2: (encoded_label, pathway)
                    raise ValueError('Expected a list of tuple pairs: encoded '+\
                        'label and associated pathway. Received tuple of length ', len(item))
                # checks to ensure encoded label comes first
                if isinstance(
                        item[0],
                        int) or isinstance(item[0], str) and item[0].isdigit():
                    # ensure pathway is string, not pathlib (for iteration purposes)
                    other_lists_files.append(str(item[1]))
        elif isinstance(l[0], str) or isinstance(
                l[0], pathlib.PosixPath) or isinstance(l[0], pathlib.PurePath):
            other_lists_files.append(l)
    # ensure list of lists is flat list
    flatten = lambda l: [item for sublist in l for item in sublist]
    other_lists_files = flatten(other_lists_files)
    contanimated_files = []
    for item in list1_files:
        if isinstance(item, str):
            item = sp.string2pathlib(item)
        fname = item.stem
        fname_parts = fname.split('-')
        fname_head = fname_parts[:-1]
        fname_head = '-'.join(fname_head)
        for i in other_lists_files:
            if fname_head in i:
                contanimated_files.append(item)
                break
    return contanimated_files
Ejemplo n.º 2
0
        pass
    except SyntaxError:
        pass

#########################################################
# For the purposes of plotting, let's use some of the settings defined:
feature_type = feat_settings['feature_type']
sr = feat_settings['sr']

######################################################
# Provide new audio for the denoiser to denoise!
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#########################################################
# We'll use sample speech from the soundpy repo:
speech = sp.string2pathlib('{}audiodata/python.wav'.format(sp_dir))
s, sr = sp.loadsound(speech, sr=sr)

#########################################################
# Let's add some white noise (10 SNR)
s_n = sp.augment.add_white_noise(s, sr=sr, snr=10)

##############################################################
# What does the noisy audio sound like?
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ipd.Audio(s_n, rate=sr)

##############################################################
# What does the noisy audio look like?
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sp.plotsound(s_n, sr=sr, feature_type='signal', subprocess=True)
Ejemplo n.º 3
0
# Let's import soundpy, and ipd for playing audio data
import soundpy as sp
import IPython.display as ipd

######################################################
# Define the noisy and clean speech audio files.
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# Note: these files are available in the soundpy repo.
# Designate path relevant for accessing audiodata
sp_dir = '../../../'

##########################################################
# Noise sample:
noise = '{}audiodata/background_samples/traffic.wav'.format(sp_dir)
noise = sp.string2pathlib(noise)
speech = '{}audiodata/python.wav'.format(sp_dir)
speech = sp.utils.string2pathlib(speech)

##########################################################
# For filtering, we will set the sample rate to be quite high:
sr = 48000

##########################################################
# Create noisy speech signal as SNR 10
noisy, snr_measured = sp.dsp.add_backgroundsound(speech,
                                                 noise,
                                                 sr=sr,
                                                 snr=10,
                                                 total_len_sec=2,
                                                 pad_mainsound_sec=0.5)