Audio processors: `apply_chat_template()` defaults to 16kHz sampling rate, even if the processor config sets a different value
Author: rmclarke
Pull request: no
Labels: name: bug

Firstly, thanks for a fantastic library!

### System Info

- `transformers` version: 4.57.5
- Platform: macOS-26.2-arm64-arm-64bit-Mach-O
- Python version: 3.14.2
- Huggingface_hub version: 0.36.0
- Safetensors version: 0.7.0
- Accelerate version: not installed
- Accelerate config: not found
- DeepSpeed version: not installed
- PyTorch version (accelerator?): 2.9.1 (NA)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: No

### Who can help?

Assuming processors fall under tokenisers: @ArthurZucker and @itazap

### Information

- [ ] The official example scripts
- [x] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [x] My own task or dataset (give details below)

### Reproduction

When using a subclass of `transformers.processing_utils.ProcessorMixin` to load an audio file with `apply_chat_template()`, if no sampling rate is explicitly specified, a default of 16kHz is used, even if the processor config calls for a different sampling rate.

Using `CsmProcessor` as an example:
```python
# pip install transformers torch scipy librosa

import torch
from transformers import AutoProcessor
import scipy.io.wavfile

# Create example audio
audio = torch.randn(24000)  # 1s of audio at 24kHz
scipy.io.wavfile.write(filename="./example.wav", rate=24000, data=audio.numpy())

# Setup processor
chat_messages = [
    dict(
        role="0",
        content=[
            {"type": "text", "text": "Example"},
            {"type": "audio", "path": "./example.wav"},
        ],
    )
]
processor = AutoProcessor.from_pretrained("sesame/csm-1b")
print(f"{processor.feature_extractor.sampling_rate=}")  # 24000
print()

# Load audio
batch = processor.apply_chat_template(
    chat_messages,
    return_dict=True,
    return_tensors="pt",
    tokenize=True,
)
print("batch['input_values'] should contain 24000 elements")
print(f"{batch['input_values'].shape=}")  # 16000 - bug
print()

# Load audio again, specifying correct rate
batch = processor.apply_chat_template(
    chat_messages,
    return_dict=True,
    return_tensors="pt",
    tokenize=True,
    sampling_rate=processor.feature_extractor.sampling_rate,
)
print("batch['input_values'] should contain 24000 elements")
print(f"{batch['input_values'].shape=}")  # 24000 - correct
```

The default is specified in `transformers.processing_utils.ChatTemplateLoadKwargs`, and is used whenever the `sampling_rate` parameter is not provided in the call to `apply_chat_template()`.

### Expected behavior

Ideally, the default sampling rate should be that of the processor subclass' config.

I'm not sure how would be neatest to implement this - possibly by overriding `apply_chat_template()` in the processor subclasses to inject a custom default value?

Comments:
@rmclarke I opened a PR which updates the default behavior so apply_chat_template() uses processor.feature_extractor.sampling_rate when available, falling back to 16kHz only if no feature extractor is present. Hope this resolves it!

Yes, I reckon that would fix it!