Example #1
0
def test_crm(tmpdir):
    """Test CRM Corpus functions."""
    fs = 40000  # native rate, to avoid large resampling delay in testing
    crm_info()
    tempdir = str(tmpdir)

    # corpus prep
    talkers = [dict(sex='f', talker_num=0)]

    crm_prepare_corpus(fs, path_out=tempdir, talker_list=talkers,
                       n_jobs=1)
    crm_prepare_corpus(fs, path_out=tempdir, talker_list=talkers, n_jobs=1,
                       overwrite=True)
    # no overwrite
    pytest.raises(RuntimeError, crm_prepare_corpus, fs, path_out=tempdir)

    # load sentence from hard drive
    crm_sentence(fs, 'f', 0, 0, 0, 0, 0, ramp_dur=0, path=tempdir)
    crm_sentence(fs, 1, '0', 'charlie', 'red', '5', stereo=True, path=tempdir)
    # bad value requested
    pytest.raises(ValueError, crm_sentence, fs, 1, 0, 0, 'periwinkle', 0,
                  path=tempdir)
    # unprepared talker
    pytest.raises(RuntimeError, crm_sentence, fs, 'm', 0, 0, 0, 0,
                  path=tempdir)
    # unprepared sampling rate
    pytest.raises(RuntimeError, crm_sentence, fs + 1, 0, 0, 0, 0, 0,
                  path=tempdir)

    # CRMPreload class
    crm = CRMPreload(fs, path=tempdir)
    crm.sentence('f', 0, 0, 0, 0)
    # unprepared sampling rate
    pytest.raises(RuntimeError, CRMPreload, fs + 1)
    # bad value requested
    pytest.raises(ValueError, crm.sentence, 1, 0, 0, 'periwinkle', 0)
    # unprepared talker
    pytest.raises(RuntimeError, crm.sentence, 'm', 0, 0, 0, 0)
    # try to specify parameters like fs, stereo, etc.
    pytest.raises(TypeError, crm.sentence, fs, '1', '0', 'charlie', 'red', '5')

    # add_pad
    x1 = np.zeros(10)
    x2 = np.ones((2, 5))
    x = add_pad([x1, x2])
    assert (np.sum(x[..., -1] == 0))
    x = add_pad((x1, x2), 'center')
    assert (np.sum(x[..., -1] == 0) and np.sum(x[..., 0] == 0))
    x = add_pad((x1, x2), 'end')
    assert (np.sum(x[..., 0] == 0))
Example #2
0
def test_crm():
    """Test CRM Corpus functions."""
    fs = 40000  # native rate, to avoid large resampling delay in testing
    crm_info()
    tempdir = _TempDir()

    # corpus prep
    talkers = [dict(sex='f', talker_num=0)]

    crm_prepare_corpus(fs, path_out=tempdir, talker_list=talkers,
                       n_jobs=np.inf)
    crm_prepare_corpus(fs, path_out=tempdir, talker_list=talkers,
                       overwrite=True)
    # no overwrite
    assert_raises(RuntimeError, crm_prepare_corpus, fs, path_out=tempdir)

    # load sentence from hard drive
    crm_sentence(fs, 'f', 0, 0, 0, 0, 0, ramp_dur=0, path=tempdir)
    crm_sentence(fs, 1, '0', 'charlie', 'red', '5', stereo=True, path=tempdir)
    # bad value requested
    assert_raises(ValueError, crm_sentence, fs, 1, 0, 0, 'periwinkle', 0,
                  path=tempdir)
    # unprepared talker
    assert_raises(RuntimeError, crm_sentence, fs, 'm', 0, 0, 0, 0,
                  path=tempdir)
    # unprepared sampling rate
    assert_raises(RuntimeError, crm_sentence, fs + 1, 0, 0, 0, 0, 0,
                  path=tempdir)

    # CRMPreload class
    crm = CRMPreload(fs, path=tempdir)
    crm.sentence('f', 0, 0, 0, 0)
    # unprepared sampling rate
    assert_raises(RuntimeError, CRMPreload, fs + 1)
    # bad value requested
    assert_raises(ValueError, crm.sentence, 1, 0, 0, 'periwinkle', 0)
    # unprepared talker
    assert_raises(RuntimeError, crm.sentence, 'm', 0, 0, 0, 0)
    # try to specify parameters like fs, stereo, etc.
    assert_raises(TypeError, crm.sentence, fs, '1', '0', 'charlie', 'red', '5')

    # add_pad
    x1 = np.zeros(10)
    x2 = np.ones((2, 5))
    x = add_pad([x1, x2])
    assert_true(np.sum(x[..., -1] == 0))
    x = add_pad((x1, x2), 'center')
    assert_true(np.sum(x[..., -1] == 0) and np.sum(x[..., 0] == 0))
    x = add_pad((x1, x2), 'end')
    assert_true(np.sum(x[..., 0] == 0))
Example #3
0
# sampling rate.
#
# .. note:: For your experiment, you only need to prepare the corpus once per
#           sampling rate, you should probably use the default path, and you
#           should just do all the talkers at once. For the example, we are
#           using fs=40000 and only doing two talkers so that the stimulus
#           preparation is very fast, and a temp directory so that we don't
#           interfere with any other prepared corpuses. Your code will likely
#           look like this line, and not appear in your actual experiment
#           script::
#
#               >>> crm_prepare_corpus(24414)
#

crm_prepare_corpus(fs, path_out=crm_path, overwrite=True,
                   talker_list=[dict(sex=0, talker_num=0),
                                dict(sex=1, talker_num=0)])

# print the valid callsigns
print('Valid callsigns are {0}'.format(crm_info()['callsign']))

# read a sentence in from the hard drive
x1 = 0.5 * crm_sentence(fs, 'm', '0', 'c', 'r', '5', path=crm_path)

# preload all the talkers and get a second sentence from memory
crm = CRMPreload(fs, path=crm_path)
x2 = crm.sentence('f', '0', 'ringo', 'green', '6')

x = add_pad([x1, x2], alignment='start')

###############################################################################
Example #4
0
#
# .. note:: For your experiment, you only need to prepare the corpus once per
#           sampling rate, you should probably use the default path, and you
#           should just do all the talkers at once. For the example, we are
#           using fs=40000 and only doing two talkers so that the stimulus
#           preparation is very fast, and a temp directory so that we don't
#           interfere with any other prepared corpuses. Your code will likely
#           look like this line, and not appear in your actual experiment
#           script::
#
#               >>> crm_prepare_corpus(24414)
#

crm_prepare_corpus(
    fs,
    path_out=crm_path,
    overwrite=True,
    talker_list=[dict(sex=0, talker_num=0),
                 dict(sex=1, talker_num=0)])

# print the valid callsigns
print('Valid callsigns are {0}'.format(crm_info()['callsign']))

# read a sentence in from the hard drive
x1 = 0.5 * crm_sentence(fs, 'm', '0', 'c', 'r', '5', path=crm_path)

# preload all the talkers and get a second sentence from memory
crm = CRMPreload(fs, path=crm_path)
x2 = crm.sentence('f', '0', 'ringo', 'green', '6')

x = add_pad([x1, x2], alignment='start')