diart.inference#

Module Contents#

Classes#

StreamingInference

Performs inference in real time given a pipeline and an audio source.

Benchmark

Run an online speaker diarization pipeline on a set of audio files in batches.

Parallelize

Wrapper to parallelize the execution of a Benchmark instance.

class diart.inference.StreamingInference(pipeline, source, batch_size=1, do_profile=True, do_plot=False, show_progress=True, progress_bar=None)#

Performs inference in real time given a pipeline and an audio source. Streams an audio source to an online speaker diarization pipeline. It allows users to attach a chain of operations in the form of hooks.

Parameters:
  • pipeline (StreamingPipeline) – Configured speaker diarization pipeline.

  • source (AudioSource) – Audio source to be read and streamed.

  • batch_size (int) – Number of inputs to send to the pipeline at once. Defaults to 1.

  • do_profile (bool) – If True, compute and report the processing time of the pipeline. Defaults to True.

  • do_plot (bool) – If True, draw predictions in a moving plot. Defaults to False.

  • show_progress (bool) – If True, show a progress bar. Defaults to True.

  • progress_bar (Optional[diart.progress.ProgressBar]) – Progress bar. If description is not provided, set to ‘Streaming <source uri>’. Defaults to RichProgressBar().

_close_pbar()#
_close_chronometer()#
attach_hooks(*hooks)#

Attach hooks to the pipeline.

Parameters:

*hooks ((Tuple[Annotation, SlidingWindowFeature]) -> None) – Hook functions to consume emitted annotations and audio.

attach_observers(*observers)#

Attach rx observers to the pipeline.

Parameters:

*observers (Observer) – Observers to consume emitted annotations and audio.

_handle_error(error)#
Parameters:

error (BaseException) –

_handle_completion()#
__call__()#

Stream audio chunks from source to pipeline.

Returns:

predictions – Speaker diarization pipeline predictions

Return type:

Annotation

class diart.inference.Benchmark(speech_path, reference_path=None, output_path=None, show_progress=True, show_report=True, batch_size=32)#

Run an online speaker diarization pipeline on a set of audio files in batches. Write predictions to a given output directory.

If the reference is given, calculate the average diarization error rate.

Parameters:
  • speech_path (Text or Path) – Directory with audio files.

  • reference_path (Text, Path or None) – Directory with reference RTTM files (same names as audio files). If None, performance will not be calculated. Defaults to None.

  • output_path (Text, Path or None) – Output directory to store predictions in RTTM format. If None, predictions will not be written to disk. Defaults to None.

  • show_progress (bool) – Whether to show progress bars. Defaults to True.

  • show_report (bool) – Whether to print a performance report to stdout. Defaults to True.

  • batch_size (int) – Inference batch size. If < 2, then it will run in real time. If >= 2, then it will pre-calculate segmentation and embeddings, running the rest in real time. The performance between this two modes does not differ. Defaults to 32.

get_file_paths()#

Return the path for each file in the benchmark.

Returns:

paths – List of audio file paths.

Return type:

List[Path]

run_single(pipeline, filepath, progress_bar)#

Run a given pipeline on a given file. Note that this method does NOT reset the state of the pipeline before execution.

Parameters:
  • pipeline (StreamingPipeline) – Speaker diarization pipeline to run.

  • filepath (Path) – Path to the target file.

  • progress_bar (diart.progress.ProgressBar) – An object to manage the progress of this run.

Returns:

prediction – Pipeline prediction for the given file.

Return type:

Annotation

evaluate(predictions, metric)#

If a reference path was provided, compute the diarization error rate of a list of predictions.

Parameters:
  • predictions (List[Annotation]) – Predictions to evaluate.

  • metric (BaseMetric) – Evaluation metric from pyannote.metrics.

Returns:

report_or_predictions – A performance report as a pandas DataFrame if a reference path was given. Otherwise return the same predictions.

Return type:

Union[pd.DataFrame, List[Annotation]]

__call__(pipeline_class, config, metric=None)#

Run a given pipeline on a set of audio files. The internal state of the pipeline is reset before benchmarking.

Parameters:
  • pipeline_class (class) – Class from the StreamingPipeline hierarchy. A pipeline from this class will be instantiated by each worker.

  • config (StreamingConfig) – Streaming pipeline configuration.

  • metric (Optional[BaseMetric]) – Evaluation metric from pyannote.metrics. Defaults to the pipeline’s suggested metric (see StreamingPipeline.suggest_metric())

Returns:

performance – If reference annotations are given, a DataFrame with detailed performance on each file as well as average performance.

If no reference annotations, a list of predictions.

Return type:

pandas.DataFrame or List[Annotation]

class diart.inference.Parallelize(benchmark, num_workers=4)#

Wrapper to parallelize the execution of a Benchmark instance. Note that models will be copied in each worker instead of being reused.

Parameters:
  • benchmark (Benchmark) – Benchmark instance to execute in parallel.

  • num_workers (int) – Number of parallel workers. Defaults to 0 (no parallelism).

run_single_job(pipeline_class, config, filepath, description)#

Build and run a pipeline on a single file. Configure execution to show progress alongside parallel runs.

Parameters:
  • pipeline_class (class) – Class from the StreamingPipeline hierarchy. A pipeline from this class will be instantiated.

  • config (StreamingConfig) – Streaming pipeline configuration.

  • filepath (Path) – Path to the target file.

  • description (Text) – Description to show in the parallel progress bar.

Returns:

prediction – Pipeline prediction for the given file.

Return type:

Annotation

__call__(pipeline_class, config, metric=None)#

Run a given pipeline on a set of audio files in parallel. Each worker will build and run the pipeline on a different file.

Parameters:
  • pipeline_class (class) – Class from the StreamingPipeline hierarchy. A pipeline from this class will be instantiated by each worker.

  • config (StreamingConfig) – Streaming pipeline configuration.

  • metric (Optional[BaseMetric]) – Evaluation metric from pyannote.metrics. Defaults to the pipeline’s suggested metric (see StreamingPipeline.suggest_metric())

Returns:

performance – If reference annotations are given, a DataFrame with detailed performance on each file as well as average performance.

If no reference annotations, a list of predictions.

Return type:

pandas.DataFrame or List[Annotation]