[Misc] Clarify mono audio requirement (#50141)

Signed-off-by: NickLucche <nicolo.lucchesi@mistral.ai>
This commit is contained in:
Nicolò Lucchesi
2026-07-31 10:46:53 +00:00
committed by GitHub
parent 6e311c6e20
commit 17beffd55f
4 changed files with 31 additions and 5 deletions
@@ -178,6 +178,7 @@ class SpeechToTextBaseServing(GenerateBaseServing):
y, sr = load_audio(
buf,
sr=self.asr_config.sample_rate,
mono=True,
max_duration_s=self.max_audio_decode_duration_s,
)
except ValueError:
+12 -5
View File
@@ -336,8 +336,8 @@ def split_audio(
for splitting.
Args:
audio_data: Audio array to split. Can be 1D (mono) or multi-dimensional.
Splits along the last dimension (time axis).
audio_data: 1D mono audio array to split. ASR models consume mono, so
callers must downmix before chunking.
sample_rate: Sample rate of the audio in Hz.
max_clip_duration_s: Maximum duration of each chunk in seconds.
overlap_duration_s: Overlap duration in seconds between consecutive chunks.
@@ -345,8 +345,10 @@ def split_audio(
min_energy_window_size: Window size in samples for finding low-energy regions.
Returns:
List of audio chunks. Each chunk is a numpy array with the same shape
as the input except for the last (time) dimension.
List of 1D audio chunks.
Raises:
AssertionError: If ``audio_data`` is not 1D.
Example:
>>> audio = np.random.randn(1040000) # 65 seconds at 16kHz
@@ -360,6 +362,11 @@ def split_audio(
>>> len(chunks)
3
"""
if audio_data.ndim > 1:
raise ValueError(
f"split_audio expects mono audio, got shape {audio_data.shape}"
)
chunk_size = int(sample_rate * max_clip_duration_s)
overlap_size = int(sample_rate * overlap_duration_s)
chunks = []
@@ -402,7 +409,7 @@ def find_split_point(
RMS energy in sliding windows.
Args:
wav: Audio array. Can be 1D or multi-dimensional.
wav: 1D mono audio array.
start_idx: Start index of search region (inclusive).
end_idx: End index of search region (exclusive).
min_energy_window: Window size in samples for energy calculation.