Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/transformers/models/voxtral/processing_voxtral.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,20 @@ def apply_transcription_request(
]
else:
audio = make_list_of_audio(audio)
if format is None:
raise ValueError("`format` must be provided when passing audio arrays to VoxtralProcessor.")

if isinstance(format, str):
format = [format] * len(audio)

if len(audio) != len(format):
raise ValueError(
f"When passed as a list of audio, the length ({len(audio)}) must match the number of format ({len(format)})"
)

if not is_soundfile_available():
raise ImportError("Please install `soundfile` to encode audio arrays with VoxtralProcessor.")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be replace with requires_backend when #47113 is merged (other fixed there is this get merged before)


audio_buffers = []
for array, f in zip(audio, format):
# Create new BytesIO object and write audio data to it
Expand Down
18 changes: 18 additions & 0 deletions tests/models/voxtral/test_modeling_voxtral.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import unittest

import numpy as np

from transformers import (
AutoProcessor,
LlamaConfig,
Expand All @@ -27,10 +29,12 @@
from transformers.testing_utils import (
Expectations,
cleanup,
require_mistral_common,
require_torch,
slow,
torch_device,
)
from transformers.utils import is_soundfile_available

from ...alm_tester import ALMModelTest, ALMModelTester

Expand Down Expand Up @@ -380,6 +384,20 @@ def test_mini_multi_turn_text_and_audio(self):
]
self.assertEqual(decoded_outputs, EXPECTED_OUTPUT)

@slow
@require_mistral_common
@unittest.skipUnless(is_soundfile_available(), "test requires soundfile")
def test_transcription_request_accepts_single_format_for_array_audio(self):
processor = AutoProcessor.from_pretrained(self.checkpoint_name)
audio = np.zeros(16000, dtype=np.float32)

inputs = processor.apply_transcription_request(
audio=audio, model_id=self.checkpoint_name, sampling_rate=16000, format="wav"
)

self.assertIn("input_features", inputs)
self.assertEqual(inputs["input_features"].shape[0], 1)

@slow
def test_transcribe_mode_audio_input(self):
"""
Expand Down
Loading