The error caused by the missing espeak library
Author: szxysdt
Pull request: no
Labels: name: bug

### System Info

**System Info**

- `transformers` version: 4.46.2
- Platform: Linux-5.4.0-198-generic-x86_64-with-glibc2.35
- Python version: 3.11.9
- Huggingface_hub version: 0.26.2
- Safetensors version: 0.4.5
- Accelerate version: not installed
- Accelerate config: not found
- PyTorch version (GPU?): 2.4.0 (True)
- 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?: <fill in>
- Using GPU in script?: <fill in>
- GPU type: Tesla V100-SXM2-16GB

### Who can help?

_No response_

### Information

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

### Tasks

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

### Reproduction

1. **Docker Image**: Use the Docker image `pytorch/pytorch:2.4.0-cuda12.4-cudnn9-devel`.

2. **Install Requirements**:
    ```
    transformers
    other necessary packages
    ```

3. **Run the First Test Code**:
    ```python
    from transformers.models.auto.tokenization_auto import AutoTokenizer as A

    b = A.from_pretrained("facebook/wav2vec2-xlsr-53-espeak-cv-ft", cache_dir=None, force_download=True, local_files_only=False, revision='main')
    print("b", b)

    # b False
    ```

4. **After Analysis**, run the following test code:
    ```python
    from transformers.models.wav2vec2_phoneme.tokenization_wav2vec2_phoneme import (
        Wav2Vec2PhonemeCTCTokenizer,
    )

    kwargs = {
        "cache_dir": None,
        "force_download": True,
        "local_files_only": False,
        "revision": "main",
        "_from_auto": True,
        "_commit_hash": None,
    }

    A = Wav2Vec2PhonemeCTCTokenizer("facebook/wav2vec2-xlsr-53-espeak-cv-ft", **kwargs)

    ```

### Expected behavior

In step 3, the Tokenizer was not loaded correctly.
Step 4 throws the following error:
```
Traceback (most recent call last):
  File "/workspace/test.py", line 14, in <module>
    A = Wav2Vec2PhonemeCTCTokenizer(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/transformers/models/wav2vec2_phoneme/tokenization_wav2vec2_phoneme.py", line 136, in __init__
    self.init_backend(self.phonemizer_lang)
  File "/opt/conda/lib/python3.11/site-packages/transformers/models/wav2vec2_phoneme/tokenization_wav2vec2_phoneme.py", line 185, in init_backend
    self.backend = BACKENDS[self.phonemizer_backend](phonemizer_lang, language_switch="remove-flags")
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/phonemizer/backend/espeak/espeak.py", line 45, in __init__
    super().__init__(
  File "/opt/conda/lib/python3.11/site-packages/phonemizer/backend/espeak/base.py", line 39, in __init__
    super().__init__(
  File "/opt/conda/lib/python3.11/site-packages/phonemizer/backend/base.py", line 77, in __init__
    raise RuntimeError(  # pragma: nocover
RuntimeError: espeak not installed on your system

```

Comments:
This problem usually appears in this form:
```
Traceback (most recent call last):
  File "/workspace/models/phone.py", line 9, in load_phone_models
    w2v_processor = Wav2Vec2Processor.from_pretrained("models/facebook/wav2vec2-xlsr-53-espeak-cv-ft")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/transformers/models/wav2vec2/processing_wav2vec2.py", line 59, in from_pretrained
    return super().from_pretrained(pretrained_model_name_or_path, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/transformers/processing_utils.py", line 948, in from_pretrained
    return cls.from_args_and_dict(args, processor_dict, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/transformers/processing_utils.py", line 746, in from_args_and_dict
    processor = cls(*args, **processor_dict)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/transformers/models/wav2vec2/processing_wav2vec2.py", line 52, in __init__
    super().__init__(feature_extractor, tokenizer)
  File "/opt/conda/lib/python3.11/site-packages/transformers/processing_utils.py", line 387, in __init__
    raise TypeError(
TypeError: Received a bool for argument tokenizer, but a PreTrainedTokenizerBase was expected.
```

When this problem occurs, a certain AutoTokenizer fails to load the tokenizer correctly and returns False (without raising an error from the AutoTokenizer itself).

---
### Solution
The reason for this error is that the `espeak` software package is not installed.

However, the `AutoTokenizer` from the `transformers` library does not seem to throw this error (I'm not sure where in the code this error is being intercepted).

At a lower level, in the implementation of `Wav2Vec2PhonemeCTCTokenizer`, the error is triggered normally and it informs me that the `espeak` package is missing.

Given that this error is so subtle and considering that the debugging environment is inside a Docker container, I am sharing the solution to this problem in hopes that it will be helpful.


I'm not sure i understand the error resolution here.  Here is my setup:

- `transformers` version: 4.46.2
- Platform: macOS-15.1-arm64-arm-64bit
- Python version: 3.12.7
- Huggingface_hub version: 0.26.2
- Safetensors version: 0.4.5
- Accelerate version: not installed
- Accelerate config: not found
- PyTorch version (GPU?): 2.5.1 (False)
- 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
Here is how i get this error:

>>> from transformers import Wav2Vec2Processor
>>> processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-lv-60-espeak-cv-ft")
preprocessor_config.json: 100%|█████████████████████████████████████████| 212/212 [00:00<00:00, 351kB/s]
tokenizer_config.json: 100%|███████████████████████████████████████████| 321/321 [00:00<00:00, 4.01MB/s]
vocab.json: 100%|██████████████████████████████████████████████████| 4.64k/4.64k [00:00<00:00, 11.3MB/s]
special_tokens_map.json: 100%|████████████████████████████████████████| 85.0/85.0 [00:00<00:00, 475kB/s]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/adelgiudice/Documents/repos/ai-asr/venv/lib/python3.12/site-packages/transformers/models/wav2vec2/processing_wav2vec2.py", line 59, in from_pretrained
    return super().from_pretrained(pretrained_model_name_or_path, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adelgiudice/Documents/repos/ai-asr/venv/lib/python3.12/site-packages/transformers/processing_utils.py", line 947, in from_pretrained
    return cls.from_args_and_dict(args, processor_dict, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adelgiudice/Documents/repos/ai-asr/venv/lib/python3.12/site-packages/transformers/processing_utils.py", line 745, in from_args_and_dict
    processor = cls(*args, **processor_dict)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adelgiudice/Documents/repos/ai-asr/venv/lib/python3.12/site-packages/transformers/models/wav2vec2/processing_wav2vec2.py", line 52, in __init__
    super().__init__(feature_extractor, tokenizer)
  File "/Users/adelgiudice/Documents/repos/ai-asr/venv/lib/python3.12/site-packages/transformers/processing_utils.py", line 387, in __init__
    raise TypeError(
TypeError: Received a bool for argument tokenizer, but a PreTrainedTokenizerBase was expected.

On a different machine I run the same two lines of python and i get no errors.  I don't recall ever installing an 'espeak' software package and the model card doesn't suggest it's necessary.  What's happening?

@adelgiudice 
In the Hugging Face library, this package has not been validated and does not throw an intuitive error. A certain section of the code directly returns a "None" (actually, this is because the `espeak` package is missing, causing the inner code to fail to execute correctly).
You can try the test code I provided, which will help you pinpoint the issue more accurately.
This environment missing issue is quite hidden and requires a bit more time to identify.