def deserialize_item(data: dict) -> Any: # Figures out what type of manifest is being decoded with some heuristics # and returns a Lhotse manifest object rather than a raw dict. from lhotse import Features, MonoCut, Recording, SupervisionSegment from lhotse.array import deserialize_array from lhotse.cut import MixedCut if "shape" in data or "array" in data: return deserialize_array(data) if "sources" in data: return Recording.from_dict(data) if "num_features" in data: return Features.from_dict(data) if "type" not in data: return SupervisionSegment.from_dict(data) cut_type = data.pop("type") if cut_type == "MonoCut": return MonoCut.from_dict(data) if cut_type == "Cut": warnings.warn( "Your manifest was created with Lhotse version earlier than v0.8, when MonoCut was called Cut. " "Please re-generate it with Lhotse v0.8 as it might stop working in a future version " "(using manifest.from_file() and then manifest.to_file() should be sufficient)." ) return MonoCut.from_dict(data) if cut_type == "MixedCut": return MixedCut.from_dict(data) raise ValueError( f"Unexpected cut type during deserialization: '{cut_type}'")
def simple_mixed_cut(): return MixedCut(id='simple-mixed-cut', tracks=[ MixTrack(cut=dummy_cut('cut0', duration=10.0)), MixTrack(cut=dummy_cut('cut1', duration=10.0), offset=5.0), ])
def cut_set_with_mixed_cut(cut1, cut2): mixed_cut = MixedCut( id="mixed-cut-id", tracks=[MixTrack(cut=cut1), MixTrack(cut=cut2, offset=1.0, snr=10)], ) return CutSet({cut.id: cut for cut in [cut1, cut2, mixed_cut]})
def simple_mixed_cut(): return MixedCut( id="simple-mixed-cut", tracks=[ MixTrack(cut=dummy_cut(0, duration=10.0)), MixTrack(cut=dummy_cut(1, duration=10.0), offset=5.0), ], )
def deserialize_item(data: dict) -> Any: # Figures out what type of manifest is being decoded with some heuristics # and returns a Lhotse manifest object rather than a raw dict. from lhotse import Cut, Features, Recording, SupervisionSegment from lhotse.cut import MixedCut data = arr2list_recursive(data) if 'sources' in data: return Recording.from_dict(data) if 'num_features' in data: return Features.from_dict(data) if 'type' not in data: return SupervisionSegment.from_dict(data) cut_type = data.pop('type') if cut_type == 'Cut': return Cut.from_dict(data) if cut_type == 'MixedCut': return MixedCut.from_dict(data) raise ValueError(f"Unexpected cut type during deserialization: '{cut_type}'")
def deserialize_item(data: dict) -> Any: # Figures out what type of manifest is being decoded with some heuristics # and returns a Lhotse manifest object rather than a raw dict. from lhotse import MonoCut, Features, Recording, SupervisionSegment from lhotse.cut import MixedCut data = arr2list_recursive(data) if 'sources' in data: return Recording.from_dict(data) if 'num_features' in data: return Features.from_dict(data) if 'type' not in data: return SupervisionSegment.from_dict(data) cut_type = data.pop('type') if cut_type == 'MonoCut': return MonoCut.from_dict(data) if cut_type == 'Cut': warnings.warn('Your manifest was created with Lhotse version earlier than v0.8, when MonoCut was called Cut. ' 'Please re-generate it with Lhotse v0.8 as it might stop working in a future version ' '(using manifest.from_file() and then manifest.to_file() should be sufficient).') return MonoCut.from_dict(data) if cut_type == 'MixedCut': return MixedCut.from_dict(data) raise ValueError(f"Unexpected cut type during deserialization: '{cut_type}'")