Merge branch 'release/4.0.5'

This commit is contained in:
Hervé BREDIN committed 2026-06-22 11:28:01 +02:00
commit ab33a012fc
23 files changed
+88 -122

No files matched your search

+7 -1
View File
@@ -1,5 +1,11 @@
# CHANGELOG
## Version 4.0.5 (2026-06-22)
- improve(telemetry): reduce number of sent packages [@litdarya](https://github.com/litdarya)
- feat(cli): add `--average-case` option to `optimize` command [@antoinelaurent](https://github.com/antoinelaurent)
- fix(task): fix `Task.prepare_data` to support saving preprocessors that produce `int` values in metadata [@lylyhan](http://github.com/lylyhan)
## Version 4.0.4 (2026-02-07)
- feat(sample): add transcription of sample file
@@ -376,7 +382,7 @@ Providing `num_speakers` to [`pyannote/speaker-diarization-3.1`](https://hf.co/p
## Version 1.0 (2018-07-03)
- chore: switch from keras to pytorch (with tensorboard support)
- improve: faster & better traning (`AutoLR`, advanced learning rate schedulers, improved batch generators)
- improve: faster & better training (`AutoLR`, advanced learning rate schedulers, improved batch generators)
- feat: add tunable speaker diarization pipeline (with its own tutorial)
- chore: drop support for Python 2 (use Python 3.6 or later)
+5 -1
View File
@@ -162,6 +162,10 @@ def optimize(
case_sensitive=False,
),
] = Metric.DiarizationErrorRate,
average_case: Annotated[
bool,
typer.Option(help="Optimize for average case rather than worst case."),
] = False,
):
"""
Optimize a PIPELINE
@@ -227,7 +231,7 @@ def optimize(
study_name=study_name,
sampler=None, # TODO: support sampler
pruner=None, # TODO: support pruner
average_case=False,
average_case=average_case,
)
direction = 1 if optimized_pipeline.get_direction() == "minimize" else -1
+1 -1
View File
@@ -434,7 +434,7 @@ class Inference(BaseInference):
window is set to "sliding", this is equivalent to calling crop on
the smallest chunk that contains all chunks. In case window is set
to "whole", this is equivalent to concatenating each chunk into one
(artifical) chunk before processing it.
(artificial) chunk before processing it.
hook : callable, optional
When a callable is provided, it is called everytime a batch is processed
with two keyword arguments:
+1 -1
View File
@@ -439,7 +439,7 @@ class Pipeline(_Pipeline):
self.instantiate(default_parameters)
except ValueError:
raise RuntimeError(
"A pipeline must be instantiated with `pipeline.instantiate(paramaters)` before it can be applied. "
"A pipeline must be instantiated with `pipeline.instantiate(parameters)` before it can be applied. "
"Tried to use parameters provided by `pipeline.default_parameters()` but those are not compatible. "
)
+6 -14
View File
@@ -214,7 +214,7 @@ class Task(lightning.LightningDataModule):
duration : float, optional
Chunks duration in seconds. Defaults to two seconds (2.).
min_duration : float, optional
Sample training chunks duration uniformely between `min_duration`
Sample training chunks duration uniformly between `min_duration`
and `duration`. Defaults to `duration` (i.e. fixed length chunks).
warm_up : float or (float, float), optional
Use that many seconds on the left- and rightmost parts of each chunk
@@ -274,7 +274,6 @@ class Task(lightning.LightningDataModule):
# metadata cache
self.cache = Path(cache) if cache else cache
# batching
self.duration = duration
self.min_duration = duration if min_duration is None else min_duration
@@ -331,7 +330,6 @@ class Task(lightning.LightningDataModule):
}
"""
if self.cache:
# check if cache exists and is not empty:
if self.cache.exists() and self.cache.stat().st_size > 0:
@@ -343,7 +341,6 @@ class Task(lightning.LightningDataModule):
# if no cache was provided by user, create a temporary file
# in system directory used for temp files
self.cache = Path(mkstemp()[1])
# list of possible values for each metadata key
# (will become .prepared_data[""])
metadata_unique_values = defaultdict(list)
@@ -417,6 +414,8 @@ class Task(lightning.LightningDataModule):
metadatum[key] = metadata_unique_values[key].index(value)
elif isinstance(value, int):
if value not in metadata_unique_values[key]:
metadata_unique_values[key].append(value)
metadatum[key] = value
else:
@@ -548,13 +547,10 @@ class Task(lightning.LightningDataModule):
("database_label_idx", get_dtype(max(a[4] for a in annotations))),
("global_label_idx", get_dtype(max(a[5] for a in annotations))),
]
# save all protocol data in a dict
prepared_data = {}
# keep track of protocol name
prepared_data["protocol"] = self.protocol.name
prepared_data["audio-path"] = np.array(audios, dtype=np.str_)
audios.clear()
@@ -568,7 +564,6 @@ class Task(lightning.LightningDataModule):
annotated_regions, dtype=region_dtype
)
annotated_regions.clear()
prepared_data["audio-regions-ids"] = np.array(
audio_regions_ids, dtype=[("start", "i"), ("end", "i")]
)
@@ -585,7 +580,6 @@ class Task(lightning.LightningDataModule):
audio_segments_ids.clear()
prepared_data["metadata-values"] = metadata_unique_values
for database, labels in database_unique_labels.items():
prepared_data[f"metadata-{database}-labels"] = np.array(
labels, dtype=np.str_
@@ -594,12 +588,10 @@ class Task(lightning.LightningDataModule):
prepared_data["metadata-labels"] = np.array(unique_labels, dtype=np.str_)
unique_labels.clear()
if self.has_validation:
self.prepare_validation(prepared_data)
self.post_prepare_data(prepared_data)
# save prepared data on the disk
with open(self.cache, "wb") as cache_file:
np.savez_compressed(cache_file, **prepared_data)
@@ -612,7 +604,7 @@ class Task(lightning.LightningDataModule):
Parameters
----------
prepared_data: dict
dictionnary containing protocol data prepared by
dictionary containing protocol data prepared by
`prepare_data()`
Note
----
@@ -807,7 +799,7 @@ class Task(lightning.LightningDataModule):
return {"loss": loss}
# default training_step provided for convenience
# can obviously be overriden for each task
# can obviously be overridden for each task
def training_step(self, batch, batch_idx: int):
return self.common_step(batch, batch_idx, "train")
@@ -835,7 +827,7 @@ class Task(lightning.LightningDataModule):
return None
# default validation_step provided for convenience
# can obviously be overriden for each task
# can obviously be overridden for each task
def validation_step(self, batch, batch_idx: int):
return self.common_step(batch, batch_idx, "val")
@@ -47,16 +47,16 @@ class PyanNet(Model):
num_channels : int, optional
Number of channels. Defaults to mono (1).
sincnet : dict, optional
Keyword arugments passed to the SincNet block.
Keyword arguments passed to the SincNet block.
Defaults to {"stride": 1}.
lstm : dict, optional
Keyword arguments passed to the LSTM layer.
Defaults to {"hidden_size": 128, "num_layers": 2, "bidirectional": True},
i.e. two bidirectional layers with 128 units each.
Set "monolithic" to False to split monolithic multi-layer LSTM into multiple mono-layer LSTMs.
This may proove useful for probing LSTM internals.
This may prove useful for probing LSTM internals.
linear : dict, optional
Keyword arugments used to initialize linear layers
Keyword arguments used to initialize linear layers
Defaults to {"hidden_size": 128, "num_layers": 2},
i.e. two linear layers with 128 units each.
"""
@@ -62,9 +62,9 @@ class SSeRiouSS(Model):
Defaults to {"hidden_size": 128, "num_layers": 4, "bidirectional": True},
i.e. two bidirectional layers with 128 units each.
Set "monolithic" to False to split monolithic multi-layer LSTM into multiple mono-layer LSTMs.
This may proove useful for probing LSTM internals.
This may prove useful for probing LSTM internals.
linear : dict, optional
Keyword arugments used to initialize linear layers
Keyword arguments used to initialize linear layers
Defaults to {"hidden_size": 128, "num_layers": 2},
i.e. two linear layers with 128 units each.
"""
@@ -158,7 +158,7 @@ class SimpleSegmentationModel(Model):
"""
# extract MFCC
mfcc = self.mfcc(waveforms)
# pass MFCC sequeence into the recurrent layer
# pass MFCC sequence into the recurrent layer
output, hidden = self.lstm(rearrange(mfcc, "b c f t -> b t (c f)"))
# apply the final classifier to get logits
return self.activation(self.classifier(output))
@@ -72,19 +72,19 @@ class ToTaToNet(Model):
num_channels : int, optional
Number of channels. Defaults to mono (1).
sincnet : dict, optional
Keyword arugments passed to the SincNet block.
Keyword arguments passed to the SincNet block.
Defaults to {"stride": 1}.
linear : dict, optional
Keyword arugments used to initialize linear layers
Keyword arguments used to initialize linear layers
See ToTaToNet.LINEAR_DEFAULTS for default values.
diar : dict, optional
Keyword arguments used to initalize the average pooling in the diarization branch.
Keyword arguments used to initialize the average pooling in the diarization branch.
See ToTaToNet.DIAR_DEFAULTS for default values.
encoder_decoder : dict, optional
Keyword arguments used to initalize the encoder and decoder.
Keyword arguments used to initialize the encoder and decoder.
See ToTaToNet.ENCODER_DECODER_DEFAULTS for default values.
dprnn : dict, optional
Keyword arguments used to initalize the DPRNN model.
Keyword arguments used to initialize the DPRNN model.
See ToTaToNet.DPRNN_DEFAULTS for default values.
sample_rate : int, optional
Audio sample rate. Defaults to 16000.
@@ -208,14 +208,14 @@ class ToTaToNet(Model):
self.average_pool = nn.AvgPool1d(
self.diarization_scaling, stride=self.diarization_scaling
)
linaer_input_features = n_feats_out
linear_input_features = n_feats_out
if linear["num_layers"] > 0:
self.linear = nn.ModuleList(
[
nn.Linear(in_features, out_features)
for in_features, out_features in pairwise(
[
linaer_input_features,
linear_input_features,
]
+ [self.hparams.linear["hidden_size"]]
* self.hparams.linear["num_layers"]
@@ -108,7 +108,7 @@ class SpeechSeparation(SpeakerDiarizationMixin, Pipeline):
clustering.method : {'centroid', 'average', ...}
Linkage used for agglomerative clustering
clustering.min_cluster_size : int
Minium cluster size.
Minimum cluster size.
clustering.threshold : float
Clustering threshold used to stop merging clusters.
separation.leakage_removal : bool
+1 -1
View File
@@ -208,7 +208,7 @@ class Hooks:
Usage
-----
>>> with Hooks(ProgessHook(), TimingHook(), ArtifactHook()) as hook:
>>> with Hooks(ProgressHook(), TimingHook(), ArtifactHook()) as hook:
... output = pipeline("audio.wav", hook=hook)
"""
@@ -50,7 +50,7 @@ class SupervisedRepresentationLearningWithArcFace(
duration : float, optional
Chunks duration in seconds. Defaults to two seconds (2.).
min_duration : float, optional
Sample training chunks duration uniformely between `min_duration`
Sample training chunks duration uniformly between `min_duration`
and `duration`. Defaults to `duration` (i.e. fixed length chunks).
num_classes_per_batch : int, optional
Number of classes per batch. Defaults to 32.
+1 -1
View File
@@ -446,7 +446,7 @@ class PixIT(SegmentationTask):
Audio chunks.
y: (frame, )
Frame-level targets. Note that frame < time.
`frame` is infered automagically from the
`frame` is inferred automagically from the
example model output.
...
"""
+1 -1
View File
@@ -1,3 +1,3 @@
metrics_enabled: true
otlp_endpoint: https://otel.pyannote.ai/v1/metrics
otlp_endpoint: https://otel.pyannote.ai/v1/traces
telemetry_log_level: CRITICAL
+41 -77
View File
@@ -22,13 +22,12 @@ from pathlib import Path
from typing import Any
from uuid import uuid4
import yaml
from opentelemetry import metrics
from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
from pyannote.audio import __version__
import numpy as np
import yaml
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from pyannote.audio import __version__
CONFIG_FILE = Path(__file__).parent / "config.yaml"
@@ -42,19 +41,11 @@ SESSION_ID = str(uuid4())
DEFAULT_LOG_LEVEL = CONFIG["telemetry_log_level"]
# Initialize metrics with basic setup
exporter = OTLPMetricExporter(endpoint=OTLP_ENDPOINT, headers=OTLP_HEADERS)
reader = PeriodicExportingMetricReader(exporter, export_interval_millis=60000)
exporter = OTLPSpanExporter(endpoint=OTLP_ENDPOINT, headers=OTLP_HEADERS, timeout=5)
provider = TracerProvider(shutdown_on_exit=False)
provider.add_span_processor(BatchSpanProcessor(exporter, schedule_delay_millis=500, export_timeout_millis=5000))
tracer = provider.get_tracer(__name__)
provider = MeterProvider(metric_readers=[reader])
metrics.set_meter_provider(provider)
meter = metrics.get_meter(__name__)
# track model initialization
model_init_counter = meter.create_counter(
name="oss-model-init",
description="Number of model initializations",
unit="1",
)
def track_model_init(model: "Model") -> None:
"""
@@ -66,22 +57,14 @@ def track_model_init(model: "Model") -> None:
Instantiated model
"""
if is_metrics_enabled():
model_init_counter.add(
1,
{
"origin": getattr(model, "_otel_origin", "unknown"),
"version": __version__,
"session_id": SESSION_ID,
},
)
# track pipeline initialization
pipeline_init_counter = meter.create_counter(
name="oss-pipeline-init",
description="Number of pipeline initializations",
unit="1",
)
with tracer.start_as_current_span("oss-model-init") as span:
span.set_attributes(
{
"origin": getattr(model, "_otel_origin", "unknown"),
"version": __version__,
"session_id": SESSION_ID,
},
)
def track_pipeline_init(pipeline: "Pipeline") -> None:
@@ -94,37 +77,16 @@ def track_pipeline_init(pipeline: "Pipeline") -> None:
Instantiated pipeline
"""
if is_metrics_enabled():
pipeline_init_counter.add(
1,
{
"origin": getattr(pipeline, "_otel_origin", "unknown"),
"name": getattr(pipeline, "_otel_name", "unknown"),
"version": __version__,
"session_id": SESSION_ID,
},
)
with tracer.start_as_current_span("oss-pipeline-init") as span:
span.set_attributes(
{
"origin": getattr(pipeline, "_otel_origin", "unknown"),
"name": getattr(pipeline, "_otel_name", "unknown"),
"version": __version__,
"session_id": SESSION_ID,
},
)
# track pipeline application
file_duration_bucket = meter.create_histogram(
name="oss-pipeline-apply",
explicit_bucket_boundaries_advisory=[
10, # 10 seconds
20, # 20 seconds
30, # 30 seconds
60, # 1 minute
120, # 2 minutes
300, # 5 minutes
600, # 10 minutes
1800, # 30 minutes
3600, # 1 hour
7200, # 2 hours
14400, # 4 hours
28800, # 8 hours
86400, # 24 hours
],
description="Duration of file in seconds",
unit="s",
)
def track_pipeline_apply(
pipeline: "Pipeline",
@@ -158,18 +120,20 @@ def track_pipeline_apply(
max_speakers=max_speakers,
)
file_duration_bucket.record(
duration,
{
"origin": getattr(pipeline, "_otel_origin", "unknown"),
"name": getattr(pipeline, "_otel_name", "unknown"),
"version": __version__,
"session_id": SESSION_ID,
"num_speakers": num_speakers,
"min_speakers": min_speakers,
"max_speakers": max_speakers if np.isfinite(max_speakers) else "inf",
},
)
with tracer.start_as_current_span("oss-pipeline-apply") as span:
span.set_attributes(
{
"origin": getattr(pipeline, "_otel_origin", "unknown"),
"name": getattr(pipeline, "_otel_name", "unknown"),
"version": __version__,
"session_id": SESSION_ID,
"duration": duration,
"num_speakers": num_speakers,
"min_speakers": min_speakers,
"max_speakers": max_speakers if np.isfinite(max_speakers) else "inf",
},
)
# Set initial metrics enabled state in env var if not already set
if "PYANNOTE_METRICS_ENABLED" not in os.environ:
@@ -189,7 +153,7 @@ def is_metrics_enabled() -> bool:
if "PYANNOTE_METRICS_ENABLED" not in os.environ:
raise ValueError("PYANNOTE_METRICS_ENABLED environment variable is not set.")
return os.environ["PYANNOTE_METRICS_ENABLED"].lower() == "true"
return os.environ["PYANNOTE_METRICS_ENABLED"].lower() in ["true", "1"]
def _save_metrics_config(enabled: bool) -> None:
+1 -1
View File
@@ -210,7 +210,7 @@ class DiscreteDiarizationErrorRate(BaseMetric):
components[name] += segment_component[name]
return components
# if (num_chunks, num_frames, num_speakers)-shaed, compute one DER per chunk and aggregate
# if (num_chunks, num_frames, num_speakers)-shared, compute one DER per chunk and aggregate
elif ndim == 3:
components = self.init_components()
+1 -1
View File
@@ -165,7 +165,7 @@ def preview(
duration = audio.get_duration(audio_file)
segment = Segment(start=0.0, end=duration)
# load waveform as SlidingWindowFeautre
# load waveform as SlidingWindowFeature
data, sample_rate = audio.crop(audio_file, segment)
data = data.numpy().T
samples = SlidingWindow(
+2 -2
View File
@@ -13,7 +13,7 @@
# Revision History
# L. Burget 20/1/2021 1:00AM - original version derived from the more
# P. Pálka 28/4/2025 17:00PM - original version derived from the more
# complex VB_diarization.py avaiable at
# complex VB_diarization.py available at
# https://github.com/BUTSpeechFIT/VBx/blob/e39af548bb41143a7136d08310765746192e34da/VBx/VB_diarization.py
# H. Bredin 12/8/2025 2:00PM - update vbx_setup signature to expect two paths
# drop HMM support
@@ -55,7 +55,7 @@ def VBx(
gamma - An initialization for the matrix of responsibilities (see Outputs: gamma)
maxIters - The maximum number of VB iterations
epsilon - Stop iterating, if the obj. fun. improvement is less than epsilon
alphaQInit - Dirichlet concentraion parameter for initializing gamma
alphaQInit - Dirichlet concentration parameter for initializing gamma
ref - T dim. integer vector with per frame reference speaker IDs (0:maxSpeakers)
plot - If set to True, plot per-frame marginal speaker posteriors 'gamma'
return_model- Return also speaker model parameter
+1 -1
View File
@@ -310,7 +310,7 @@
"id": "ISngZk15Uzhb"
},
"source": [
"Dowload a sample audio file (make sure the download link is public or your bug report will not be reproducible by anyone)."
"Download a sample audio file (make sure the download link is public or your bug report will not be reproducible by anyone)."
]
},
{
@@ -120,7 +120,7 @@
"\n",
"Pyannote uses some internal logic to determine the model type.\n",
"\n",
"The funtion `def PretrainedSpeakerEmbedding(...` in (speaker_verification.py)[https://github.com/pyannote/pyannote-audio/blob/develop/pyannote/audio/pipelines/speaker_verification.py#L712] uses the the file path of the model to infer the model type.\n",
"The function `def PretrainedSpeakerEmbedding(...` in (speaker_verification.py)[https://github.com/pyannote/pyannote-audio/blob/develop/pyannote/audio/pipelines/speaker_verification.py#L712] uses the the file path of the model to infer the model type.\n",
"\n",
"```python\n",
"def PretrainedSpeakerEmbedding(\n",
+1 -1
View File
@@ -268,7 +268,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now that everything is ready, let's train with `pytorch-ligthning`!"
"Now that everything is ready, let's train with `pytorch-lightning`!"
]
},
{
+1 -1
View File
@@ -229,7 +229,7 @@
"id": "WCNd35YInX8T"
},
"source": [
"Now that everything is ready, let's train with `pytorch-ligthning`!"
"Now that everything is ready, let's train with `pytorch-lightning`!"
]
},
{
+1 -1
View File
@@ -1 +1 @@
{"cells":[{"cell_type":"markdown","metadata":{"id":"3M4zoYI4Q-Xi"},"source":["<a href=\"https://colab.research.google.com/github/pyannote/pyannote-audio/blob/develop/tutorials/voice_activity_detection.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"]},{"cell_type":"markdown","metadata":{"id":"fEew3B3-Q-Xl"},"source":["# Training a voice activity detection pipeline from scratch with `pyannote.audio`\n","\n","Voice activity detection (VAD) is the task of detecting speech regions in a given audio stream or recording. \n","In this tutorial, you will learn how to train and evaluate a VAD pipeline from scratch."]},{"cell_type":"markdown","metadata":{"id":"1F6PKPftQ-Xm"},"source":["## Tutorial setup"]},{"cell_type":"markdown","metadata":{"id":"ErPKDILdQ-Xn"},"source":["### `Google Colab` setup"]},{"cell_type":"markdown","metadata":{"id":"SYU2JJ9-Q-Xo"},"source":["If you are running this tutorial on `Colab`, execute the following commands in order to setup `Colab` environment. These commands will install `pyannote.audio` and download a mini version of the `AMI` corpus."]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":1772401,"status":"ok","timestamp":1704890790335,"user":{"displayName":"Clément PAGES","userId":"11757386314069785178"},"user_tz":-60},"id":"EMspGag4Q-Xp","outputId":"0aaf740d-96c8-4340-a9e7-5c529f12fe9b"},"outputs":[],"source":["!pip install -qq pyannote.audio==3.1.1\n","!pip install -qq ipython==7.34.0\n","!git clone https://github.com/pyannote/AMI-diarization-setup.git\n","%cd ./AMI-diarization-setup/pyannote/\n","!bash ./download_ami_mini.sh\n","%cd /content"]},{"cell_type":"markdown","metadata":{"id":"TFqu_5vyQ-Xq"},"source":["⚠ Restart the runtime (Runtime > Restart session)."]},{"cell_type":"markdown","metadata":{"id":"7_7eodg5Q-Xr"},"source":["### Non `Google Colab` setup"]},{"cell_type":"markdown","metadata":{"id":"WCy8p55QQ-Xr"},"source":["If you are not using `Colab`, this tutorial assumes that\n","* `pyannote.audio` has been installed\n","* the [AMI corpus](https://groups.inf.ed.ac.uk/ami/corpus/) has already been [setup for use with `pyannote`](https://github.com/pyannote/AMI-diarization-setup/tree/main/pyannote)"]},{"cell_type":"markdown","metadata":{"id":"M-oe_8FFQ-Xu"},"source":["## Data preparation\n","\n","See [`pyannote.database` documentation](https://github.com/pyannote/pyannote-database#pyannote-database) to learn how to prepare your own dataset for training with `pyannote.audio`."]},{"cell_type":"code","execution_count":null,"metadata":{"id":"KBstX_2sQ-Xu"},"outputs":[],"source":["from pyannote.database import registry, FileFinder\n","\n","registry.load_database(\"AMI-diarization-setup/pyannote/database.yml\")\n","preprocessors = {\"audio\": FileFinder()}\n","ami = registry.get_protocol('AMI.SpeakerDiarization.mini',\n"," preprocessors=preprocessors)"]},{"cell_type":"markdown","metadata":{"id":"oYIKQ5kwQ-Xv"},"source":["`pyannote.database` *protocols* usually define\n","* a training set: `for training_file in protocol.train(): ...`,\n","* a validation set: `for validation_file in protocol.development(): ...`\n","* an evaluation set `for evaluation_file in protocol.test(): ...`"]},{"cell_type":"markdown","metadata":{"id":"siLd6sE3Q-Xw"},"source":["Let's listen to one minute of the first training file..."]},{"cell_type":"code","execution_count":2,"metadata":{"executionInfo":{"elapsed":212,"status":"ok","timestamp":1704890828290,"user":{"displayName":"Clément PAGES","userId":"11757386314069785178"},"user_tz":-60},"id":"bai4OplyQ-Xw"},"outputs":[],"source":["first_training_file = next(ami.train())\n","reference = first_training_file[\"annotation\"]"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":151,"output_embedded_package_id":"1GxUBhwcdeeXdLogFqdzXqSDl6FNpaR2t"},"executionInfo":{"elapsed":7227,"status":"ok","timestamp":1704890839349,"user":{"displayName":"Clément PAGES","userId":"11757386314069785178"},"user_tz":-60},"id":"5t2l6o3NQ-Xx","outputId":"9755f212-b8ca-45ad-e1a2-60f00665d7be"},"outputs":[],"source":["from pyannote.audio.utils.preview import listen\n","from pyannote.core import Segment\n","\n","one_minute = Segment(240, 300)\n","listen(first_training_file, one_minute)"]},{"cell_type":"markdown","metadata":{"id":"Z3-VQas0Q-Xy"},"source":["... and visualize the manual annotation:"]},{"cell_type":"code","execution_count":4,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":239},"executionInfo":{"elapsed":592,"status":"ok","timestamp":1704890847735,"user":{"displayName":"Clément PAGES","userId":"11757386314069785178"},"user_tz":-60},"id":"8fNi_I0pQ-Xz","outputId":"83cfee16-8a4e-4528-8a60-d5b8c0990fc7"},"outputs":[{"data":{"image/png":"iVBORw0KGgoAAAANSUhEUgAABjwAAADyCAYAAAD5q2z1AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHLine truncated
{"cells":[{"cell_type":"markdown","metadata":{"id":"3M4zoYI4Q-Xi"},"source":["<a href=\"https://colab.research.google.com/github/pyannote/pyannote-audio/blob/develop/tutorials/voice_activity_detection.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"]},{"cell_type":"markdown","metadata":{"id":"fEew3B3-Q-Xl"},"source":["# Training a voice activity detection pipeline from scratch with `pyannote.audio`\n","\n","Voice activity detection (VAD) is the task of detecting speech regions in a given audio stream or recording. \n","In this tutorial, you will learn how to train and evaluate a VAD pipeline from scratch."]},{"cell_type":"markdown","metadata":{"id":"1F6PKPftQ-Xm"},"source":["## Tutorial setup"]},{"cell_type":"markdown","metadata":{"id":"ErPKDILdQ-Xn"},"source":["### `Google Colab` setup"]},{"cell_type":"markdown","metadata":{"id":"SYU2JJ9-Q-Xo"},"source":["If you are running this tutorial on `Colab`, execute the following commands in order to setup `Colab` environment. These commands will install `pyannote.audio` and download a mini version of the `AMI` corpus."]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":1772401,"status":"ok","timestamp":1704890790335,"user":{"displayName":"Clément PAGES","userId":"11757386314069785178"},"user_tz":-60},"id":"EMspGag4Q-Xp","outputId":"0aaf740d-96c8-4340-a9e7-5c529f12fe9b"},"outputs":[],"source":["!pip install -qq pyannote.audio==3.1.1\n","!pip install -qq ipython==7.34.0\n","!git clone https://github.com/pyannote/AMI-diarization-setup.git\n","%cd ./AMI-diarization-setup/pyannote/\n","!bash ./download_ami_mini.sh\n","%cd /content"]},{"cell_type":"markdown","metadata":{"id":"TFqu_5vyQ-Xq"},"source":["⚠ Restart the runtime (Runtime > Restart session)."]},{"cell_type":"markdown","metadata":{"id":"7_7eodg5Q-Xr"},"source":["### Non `Google Colab` setup"]},{"cell_type":"markdown","metadata":{"id":"WCy8p55QQ-Xr"},"source":["If you are not using `Colab`, this tutorial assumes that\n","* `pyannote.audio` has been installed\n","* the [AMI corpus](https://groups.inf.ed.ac.uk/ami/corpus/) has already been [setup for use with `pyannote`](https://github.com/pyannote/AMI-diarization-setup/tree/main/pyannote)"]},{"cell_type":"markdown","metadata":{"id":"M-oe_8FFQ-Xu"},"source":["## Data preparation\n","\n","See [`pyannote.database` documentation](https://github.com/pyannote/pyannote-database#pyannote-database) to learn how to prepare your own dataset for training with `pyannote.audio`."]},{"cell_type":"code","execution_count":null,"metadata":{"id":"KBstX_2sQ-Xu"},"outputs":[],"source":["from pyannote.database import registry, FileFinder\n","\n","registry.load_database(\"AMI-diarization-setup/pyannote/database.yml\")\n","preprocessors = {\"audio\": FileFinder()}\n","ami = registry.get_protocol('AMI.SpeakerDiarization.mini',\n"," preprocessors=preprocessors)"]},{"cell_type":"markdown","metadata":{"id":"oYIKQ5kwQ-Xv"},"source":["`pyannote.database` *protocols* usually define\n","* a training set: `for training_file in protocol.train(): ...`,\n","* a validation set: `for validation_file in protocol.development(): ...`\n","* an evaluation set `for evaluation_file in protocol.test(): ...`"]},{"cell_type":"markdown","metadata":{"id":"siLd6sE3Q-Xw"},"source":["Let's listen to one minute of the first training file..."]},{"cell_type":"code","execution_count":2,"metadata":{"executionInfo":{"elapsed":212,"status":"ok","timestamp":1704890828290,"user":{"displayName":"Clément PAGES","userId":"11757386314069785178"},"user_tz":-60},"id":"bai4OplyQ-Xw"},"outputs":[],"source":["first_training_file = next(ami.train())\n","reference = first_training_file[\"annotation\"]"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":151,"output_embedded_package_id":"1GxUBhwcdeeXdLogFqdzXqSDl6FNpaR2t"},"executionInfo":{"elapsed":7227,"status":"ok","timestamp":1704890839349,"user":{"displayName":"Clément PAGES","userId":"11757386314069785178"},"user_tz":-60},"id":"5t2l6o3NQ-Xx","outputId":"9755f212-b8ca-45ad-e1a2-60f00665d7be"},"outputs":[],"source":["from pyannote.audio.utils.preview import listen\n","from pyannote.core import Segment\n","\n","one_minute = Segment(240, 300)\n","listen(first_training_file, one_minute)"]},{"cell_type":"markdown","metadata":{"id":"Z3-VQas0Q-Xy"},"source":["... and visualize the manual annotation:"]},{"cell_type":"code","execution_count":4,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":239},"executionInfo":{"elapsed":592,"status":"ok","timestamp":1704890847735,"user":{"displayName":"Clément PAGES","userId":"11757386314069785178"},"user_tz":-60},"id":"8fNi_I0pQ-Xz","outputId":"83cfee16-8a4e-4528-8a60-d5b8c0990fc7"},"outputs":[{"data":{"image/png":"iVBORw0KGgoAAAANSUhEUgAABjwAAADyCAYAAAD5q2z1AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHLine truncated