Skip to content

Commit

Permalink
feat(pipeline): add Waveform and SampleRate preprocessors (pyannote#1593
Browse files Browse the repository at this point in the history
)
  • Loading branch information
hbredin committed Dec 20, 2023
1 parent 4d2d16b commit 7bd88d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Changelog

## develop branch
## develop

### New features

- feat(pipeline): add `Waveform` and `SampleRate` preprocessors
- feat(model): add `num_frames` and `receptive_field` to segmentation models

## Version 3.1.1 (2023-12-01)
Expand Down
18 changes: 16 additions & 2 deletions pyannote/audio/utils/preprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
# Hervé BREDIN - http://herve.niderb.fr

from functools import reduce
from itertools import chain
from typing import Dict, List, Optional, Set

from pyannote.core import Annotation, Segment
from pyannote.database import ProtocolFile

from pyannote.audio.core.io import Audio, get_torchaudio_info


class LowerTemporalResolution:
"""Artificially degrade temporal resolution of reference annotation
Expand All @@ -50,7 +51,6 @@ def __init__(self, resolution: float = 0.1):
self.resolution = resolution

def __call__(self, current_file: ProtocolFile) -> Annotation:

annotation = current_file["annotation"]
new_annotation = annotation.empty()

Expand Down Expand Up @@ -128,3 +128,17 @@ def __call__(self, current_file: ProtocolFile) -> Annotation:
derived[seg] = intersect_label

return derived


class Waveform:
def __init__(self):
self._audio = Audio()

def __call__(self, file: ProtocolFile):
waveform, _ = self._audio(file)
return waveform


class SampleRate:
def __call__(self, file: ProtocolFile):
return get_torchaudio_info(file).sample_rate

0 comments on commit 7bd88d5

Please sign in to comment.