abdeladim-s / pywhispercpp

Python bindings for whisper.cpp
https://abdeladim-s.github.io/pywhispercpp/
MIT License
129 stars 15 forks source link

Unknown language error #5

Closed daniel112 closed 1 year ago

daniel112 commented 1 year ago

When passing in a language parameter, it doesn't seem to translate the string over properly.

Example:

Error output: whisper_lang_id: unknown language '\�'

image

abdeladim-s commented 1 year ago

You don't need the " around the language in the CLI.

Use it like the following:

pwcpp ./some_audio.wav --language es -m base --print_realtime true
daniel112 commented 1 year ago

You don't need the " around the language in the CLI.

Use it like the following:

pwcpp ./some_audio.wav --language es -m base --print_realtime true

@abdeladim-s

I tried running pwcpp ./audio-sample/wav/what-is-it-like-to-be-a-crocodile.wav -m base --print_realtime true --language en

daniel.yo@DanielYoMBP backend % pwcpp ./audio-sample/wav/what-is-it-like-to-be-a-crocodile.wav --language en -m base --print_realtime true

PyWhisperCpp
A simple Command Line Interface to test the package
Version: 1.0.6               
====================================================

[2023-03-24 19:53:27,884] {main.py:44} INFO - Running with model `base`
[2023-03-24 19:53:27,884] {main.py:46} INFO - Running with params {'print_realtime': True, 'language': 'en'}
[2023-03-24 19:53:27,884] {utils.py:38} INFO - No download directory was provided, models will be downloaded to /Users/daniel.yo/Library/Application Support/pywhispercpp/models
[2023-03-24 19:53:27,884] {utils.py:46} INFO - Model base already exists in /Users/daniel.yo/Library/Application Support/pywhispercpp/models
[2023-03-24 19:53:27,884] {model.py:221} INFO - Initializing the model ...
whisper_init_from_file: loading model from '/Users/daniel.yo/Library/Application Support/pywhispercpp/models/ggml-base.bin'
whisper_model_load: loading model
whisper_model_load: n_vocab       = 51865
whisper_model_load: n_audio_ctx   = 1500
whisper_model_load: n_audio_state = 512
whisper_model_load: n_audio_head  = 8
whisper_model_load: n_audio_layer = 6
whisper_model_load: n_text_ctx    = 448
whisper_model_load: n_text_state  = 512
whisper_model_load: n_text_head   = 8
whisper_model_load: n_text_layer  = 6
whisper_model_load: n_mels        = 80
whisper_model_load: f16           = 1
whisper_model_load: type          = 2
whisper_model_load: mem required  =  215.00 MB (+    6.00 MB per decoder)
whisper_model_load: kv self size  =    5.25 MB
whisper_model_load: kv cross size =   17.58 MB
whisper_model_load: adding 1608 extra tokens
whisper_model_load: model ctx     =  140.60 MB
whisper_model_load: model size    =  140.54 MB
Traceback (most recent call last):
  File "/opt/homebrew/bin/pwcpp", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.10/site-packages/pywhispercpp/examples/main.py", line 96, in main
    run(args)
  File "/opt/homebrew/lib/python3.10/site-packages/pywhispercpp/examples/main.py", line 48, in run
    logging.info(f"System info: n_threads = {m.get_params()['n_threads']} | Processors = {args.processors} "
  File "/opt/homebrew/lib/python3.10/site-packages/pywhispercpp/model.py", line 166, in get_params
    res[param] = getattr(self._params, param)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 1: invalid continuation byte

My original issue came from the python implementation, but I wanted to verify the CLI method as well since I can't get it to work on python.

Below is my python test implementation based on the documentation. This was spitting the Unknown Language error as well

whisper_model = Model('base', n_threads=8,
                      print_progress=False, print_realtime=False, language="fr", translate=False)
print(whisper_model.available_languages())
whisper_model.transcribe(media="./audio-sample/wav/test.wav")
abdeladim-s commented 1 year ago

Yes you are right, there was a problem with that language variable. whisper.cpp defined it as char * and not std::string, so it needed some casting from Python str .

I will push the fix now and give it another try. Don't forget to update pywhispercpp to the latest version 1.0.7

daniel112 commented 1 year ago

it looks like the new version works. thanks!