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))
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))
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') ############################################################################### # Now we actually run the experiment. max_wait = 0.01 if building_doc else 3 with ExperimentController( exp_name='CRM corpus example', window_size=(720, 480), full_screen=False, participant='foo', session='foo', version='dev', output_dir=None, stim_fs=40000) as ec: ec.screen_text('Report the color and number spoken by the female ' 'talker.', wrap=True) screenshot = ec.screenshot() ec.flip() ec.wait_secs(max_wait)
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') ############################################################################### # Now we actually run the experiment. max_wait = 0.01 if building_doc else 3 with ExperimentController(exp_name='CRM corpus example', window_size=(720, 480), full_screen=False, participant='foo', session='foo', version='dev', output_dir=None, stim_fs=40000) as ec: ec.screen_text( 'Report the color and number spoken by the female '