當前位置: 首頁>>代碼示例>>Python>>正文


Python jams.Annotation方法代碼示例

本文整理匯總了Python中jams.Annotation方法的典型用法代碼示例。如果您正苦於以下問題:Python jams.Annotation方法的具體用法?Python jams.Annotation怎麽用?Python jams.Annotation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jams的用法示例。


在下文中一共展示了jams.Annotation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_annotation_eq

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_annotation_eq(tag_data):
    namespace = 'tag_open'

    ann1 = jams.Annotation(namespace, data=tag_data)
    ann2 = jams.Annotation(namespace, data=tag_data)

    assert ann1 == ann2

    # Test the type-check in equality
    assert not (ann1 == tag_data)

    update = dict(time=2.0, duration=1.0, value='three', confidence=0.8)

    ann2.append(**update)

    assert not (ann1 == ann2) 
開發者ID:marl,項目名稱:jams,代碼行數:18,代碼來源:test_jams.py

示例2: test_jams_add

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_jams_add(tag_data):

    fn = 'tests/fixtures/valid.jams'

    # The original jam
    jam_orig = jams.load(fn)
    jam = jams.load(fn)

    # Make a new jam with the same metadata and different data
    jam2 = jams.load(fn)
    ann = jams.Annotation('tag_open', data=tag_data)
    jam2.annotations = jams.AnnotationArray(annotations=[ann])

    # Add the two
    jam.add(jam2)

    assert len(jam.annotations) == 3
    assert jam.annotations[:-1] == jam_orig.annotations
    assert jam.annotations[-1] == jam2.annotations[0] 
開發者ID:marl,項目名稱:jams,代碼行數:21,代碼來源:test_jams.py

示例3: test_annotation_trim_no_overlap

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_annotation_trim_no_overlap():
    # when there's no overlap, a warning is raised and the
    # returned annotation should be empty
    ann = jams.Annotation('tag_open')
    ann.time = 5
    ann.duration = 10

    trim_times = [(1, 2), (16, 20)]

    for tt in trim_times[:2]:

        clean_warning_registry()
        with warnings.catch_warnings(record=True) as out:
            ann_trim = ann.trim(*tt)

        assert len(out) > 0
        assert out[0].category is UserWarning
        assert 'does not intersect' in str(out[0].message).lower()

        assert len(ann_trim.data) == 0
        assert ann_trim.time == ann.time
        assert ann_trim.duration == 0 
開發者ID:marl,項目名稱:jams,代碼行數:24,代碼來源:test_jams.py

示例4: test_annotation_data_frame

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_annotation_data_frame():
    namespace = 'tag_open'
    data = dict(time=[5.0, 5.0, 10.0],
                duration=[2.0, 4.0, 4.0],
                value=['one', 'two', 'three'],
                confidence=[0.9, 0.9, 0.9])
    ann = jams.Annotation(namespace, data=data, time=5.0, duration=10.0)

    df = ann.to_dataframe()

    assert list(df.columns) == ['time', 'duration', 'value', 'confidence']

    for i, row in df.iterrows():
        assert row.time == data['time'][i]
        assert row.duration == data['duration'][i]
        assert row.value == data['value'][i]
        assert row.confidence == data['confidence'][i] 
開發者ID:marl,項目名稱:jams,代碼行數:19,代碼來源:test_jams.py

示例5: test_annotation_to_samples

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_annotation_to_samples(confidence):

    ann = jams.Annotation('tag_open')

    ann.append(time=0, duration=0.5, value='one', confidence=0.1)
    ann.append(time=0.25, duration=0.5, value='two', confidence=0.2)
    ann.append(time=0.75, duration=0.5, value='three', confidence=0.3)
    ann.append(time=1.5, duration=0.5, value='four', confidence=0.4)

    values = ann.to_samples([0.2, 0.4, 0.75, 1.25, 1.75, 1.4], confidence=confidence)

    if confidence:
        values, confs = values
        assert confs == [[0.1], [0.1, 0.2], [0.2, 0.3], [0.3], [0.4], []]

    assert values == [['one'], ['one', 'two'], ['two', 'three'], ['three'], ['four'], []] 
開發者ID:marl,項目名稱:jams,代碼行數:18,代碼來源:test_jams.py

示例6: test_ns_contour_valid

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_ns_contour_valid():

    srand()

    ann = Annotation(namespace='pitch_contour')

    seq_len = 21
    times = np.arange(seq_len)
    durations = np.zeros(seq_len)
    values = np.linspace(0, 22050, seq_len)  # includes 0 (odd symmetric)
    ids = np.arange(len(values)) // 4
    voicing = np.random.randn(len(ids)) > 0

    confidences = np.linspace(0, 1., seq_len)
    confidences[seq_len//2] = None  # throw in a None confidence value

    for (t, d, v, c, i, b) in zip(times, durations, values,
                                  confidences, ids, voicing):
        ann.append(time=t, duration=d,
                   value={'pitch': v, 'id': i, 'voiced': b}, confidence=c)

    ann.validate() 
開發者ID:marl,項目名稱:jams,代碼行數:24,代碼來源:test_ns.py

示例7: test_ns_contour_invalid

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_ns_contour_invalid():

    srand()

    ann = Annotation(namespace='pitch_contour')

    seq_len = 21
    times = np.arange(seq_len)
    durations = np.zeros(seq_len)
    values = np.linspace(0, 22050, seq_len)  # includes 0 (odd symmetric)
    ids = np.arange(len(values)) // 4
    voicing = np.random.randn(len(ids)) * 2

    confidences = np.linspace(0, 1., seq_len)
    confidences[seq_len//2] = None  # throw in a None confidence value

    for (t, d, v, c, i, b) in zip(times, durations, values,
                                  confidences, ids, voicing):
        ann.append(time=t, duration=d,
                   value={'pitch': v, 'id': i, 'voiced': b}, confidence=c)

    ann.validate() 
開發者ID:marl,項目名稱:jams,代碼行數:24,代碼來源:test_ns.py

示例8: test_ns_scaper_source_time

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_ns_scaper_source_time(source_time):

    ann = Annotation(namespace='scaper')

    value = {
        "source_time": source_time,
        "event_duration": 0.5310546236891855,
        "event_time": 5.6543442662431795,
        "time_stretch": 0.8455598669219283,
        "pitch_shift": -1.2204911976305648,
        "snr": 7.790682558359417,
        "label": 'gun_shot',
        "role": "foreground",
        "source_file": "/audio/foreground/gun_shot/135544-6-17-0.wav"
    }

    ann.append(time=0, duration=1, value=value)
    ann.validate() 
開發者ID:marl,項目名稱:jams,代碼行數:20,代碼來源:test_ns.py

示例9: test_ns_scaper_event_duration

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_ns_scaper_event_duration(event_duration):

    ann = Annotation(namespace='scaper')

    value = {
        "source_time": 0.0,
        "event_duration": event_duration,
        "event_time": 5.6543442662431795,
        "time_stretch": 0.8455598669219283,
        "pitch_shift": -1.2204911976305648,
        "snr": 7.790682558359417,
        "label": 'gun_shot',
        "role": "foreground",
        "source_file": "/audio/foreground/gun_shot/135544-6-17-0.wav"
    }

    ann.append(time=0, duration=1, value=value)
    ann.validate() 
開發者ID:marl,項目名稱:jams,代碼行數:20,代碼來源:test_ns.py

示例10: test_ns_scaper_event_time

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_ns_scaper_event_time(event_time):

    ann = Annotation(namespace='scaper')

    value = {
        "source_time": 0.0,
        "event_duration": 0.5310546236891855,
        "event_time": event_time,
        "time_stretch": 0.8455598669219283,
        "pitch_shift": -1.2204911976305648,
        "snr": 7.790682558359417,
        "label": 'gun_shot',
        "role": "foreground",
        "source_file": "/audio/foreground/gun_shot/135544-6-17-0.wav"
    }

    ann.append(time=0, duration=1, value=value)
    ann.validate() 
開發者ID:marl,項目名稱:jams,代碼行數:20,代碼來源:test_ns.py

示例11: test_ns_scaper_time_stretch

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_ns_scaper_time_stretch(time_stretch):

    ann = Annotation(namespace='scaper')

    value = {
        "source_time": 0.0,
        "event_duration": 0.5310546236891855,
        "event_time": 5.6543442662431795,
        "time_stretch": time_stretch,
        "pitch_shift": -1.2204911976305648,
        "snr": 7.790682558359417,
        "label": 'gun_shot',
        "role": "foreground",
        "source_file": "/audio/foreground/gun_shot/135544-6-17-0.wav"
    }

    ann.append(time=0, duration=1, value=value)
    ann.validate() 
開發者ID:marl,項目名稱:jams,代碼行數:20,代碼來源:test_ns.py

示例12: test_ns_scaper_pitch_shift

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_ns_scaper_pitch_shift(pitch_shift):

    ann = Annotation(namespace='scaper')

    value = {
        "source_time": 0.0,
        "event_duration": 0.5310546236891855,
        "event_time": 5.6543442662431795,
        "time_stretch": 0.8455598669219283,
        "pitch_shift": pitch_shift,
        "snr": 7.790682558359417,
        "label": 'gun_shot',
        "role": "foreground",
        "source_file": "/audio/foreground/gun_shot/135544-6-17-0.wav"
    }

    ann.append(time=0, duration=1, value=value)
    ann.validate() 
開發者ID:marl,項目名稱:jams,代碼行數:20,代碼來源:test_ns.py

示例13: test_annotation

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_annotation(namespace, tag_data, ann_metadata, ann_sandbox):
    ann = jams.Annotation(namespace, data=tag_data,
                          annotation_metadata=ann_metadata,
                          sandbox=ann_sandbox)

    assert namespace == ann.namespace

    assert dict(ann_metadata) == dict(ann.annotation_metadata)

    assert dict(ann_sandbox) == dict(ann.sandbox)

    assert len(ann.data) == len(tag_data)
    for obs1, obs2 in zip(ann.data, tag_data):
        assert obs1._asdict() == obs2 
開發者ID:marl,項目名稱:jams,代碼行數:16,代碼來源:test_jams.py

示例14: test_annotation_append

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_annotation_append():

    data = [dict(time=0, duration=0.5, value='one', confidence=0.9),
            dict(time=1.0, duration=0.5, value='two', confidence=0.9)]

    namespace = 'tag_open'

    ann = jams.Annotation(namespace, data=data)

    update = dict(time=2.0, duration=1.0, value='three', confidence=0.8)

    ann.append(**update)

    assert ann.data[-1]._asdict() == update 
開發者ID:marl,項目名稱:jams,代碼行數:16,代碼來源:test_jams.py

示例15: test_annotation_iterator

# 需要導入模塊: import jams [as 別名]
# 或者: from jams import Annotation [as 別名]
def test_annotation_iterator():

    data = [dict(time=0, duration=0.5, value='one', confidence=0.2),
            dict(time=1, duration=1, value='two', confidence=0.5)]

    namespace = 'tag_open'

    ann = jams.Annotation(namespace, data=data)

    for obs, obs_raw in zip(ann, data):
        assert isinstance(obs, jams.Observation)
        assert obs._asdict() == obs_raw, (obs, obs_raw) 
開發者ID:marl,項目名稱:jams,代碼行數:14,代碼來源:test_jams.py


注:本文中的jams.Annotation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。