From a0760513abe455b36bfe5b3e3b5aedf4ad2c55e3 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Wed, 18 Jun 2025 16:47:11 +0800 Subject: [PATCH] Fixes #2172 Handle the case when the input audio contains no speeches. --- sherpa-onnx/csrc/offline-speaker-diarization-pyannote-impl.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sherpa-onnx/csrc/offline-speaker-diarization-pyannote-impl.h b/sherpa-onnx/csrc/offline-speaker-diarization-pyannote-impl.h index e8228d47bf..8573c74946 100644 --- a/sherpa-onnx/csrc/offline-speaker-diarization-pyannote-impl.h +++ b/sherpa-onnx/csrc/offline-speaker-diarization-pyannote-impl.h @@ -160,6 +160,11 @@ class OfflineSpeakerDiarizationPyannoteImpl std::vector cluster_labels = clustering_->Cluster( &embeddings(0, 0), embeddings.rows(), embeddings.cols()); + if (cluster_labels.empty()) { + SHERPA_ONNX_LOGE("No speakers found in the audio samples"); + return {}; + } + int32_t max_cluster_index = *std::max_element(cluster_labels.begin(), cluster_labels.end());