Repository: aarnphm/whispercpp (language: python)

Issue:
bug: Cannot change transcription language
### Describe the bug

Even if the original audio is not an English speech, the transcription is always translated in English.
I've tried to change the `language` property of `params`  using `api.Params.language = 'it'` but it didn't work.

### To reproduce

```
import ffmpeg
import numpy as np
from whispercpp import Whisper
from whispercpp import api

try:
    y, _ = (
        ffmpeg.input("/Users/michelangelopucci/Downloads/untitled folder 2/output.wav", threads=0)
        .output("-", format="s16le", acodec="pcm_s16le", ac=1)
        .run(
            cmd=["ffmpeg", "-nostdin"], capture_stdout=True, capture_stderr=True
        )
    )
except ffmpeg.Error as e:
    raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e

arr = np.frombuffer(y, np.int16).flatten().astype(np.float32) / 32768.0

api.Params.language = 'it'
w = Whisper.from_pretrained("large")
a = w.transcribe(arr)
print(a)
```

### Expected behavior

_No response_

### Environment

Python 3.9.6


Discussion / hints:
You have to change it from the `Whisper` instance

```python
w = w.Whisper.from_pretrained("tiny")
w.params.language = "it"
w.transcribe(arr)
```
Well, I tried also doing that, however I get this error `whisper_lang_id: unknown language 'ӄ'`
In fact, after the language property is edited, accessing to `w.params.language` gets `UnicodeDecodeError: 'utf-8' codec can't decode byte 0xce in position 0: invalid continuation byte`
I think there is a bug with the params c_str right now. Feel free to put up a PR to fix it. It is in `src/whispercpp/api_export.cc` for the `Params` obj.
Wish I could but I cannot... Hope someone else can fix this soon!

Fix patch:
diff --git a/src/whispercpp/context.h b/src/whispercpp/context.h
index d630f84..9f49b93 100644
--- a/src/whispercpp/context.h
+++ b/src/whispercpp/context.h
@@ -139,6 +139,7 @@ struct Params {
 
 private:
   std::shared_ptr<whisper_full_params> fp;
+  std::string language;
 
   CallbackAndContext<NewSegmentCallback> new_segment_callback;
 
@@ -332,8 +333,9 @@ struct Params {
   // Set target language.
   // For auto-detection, set this either to 'auto' or nullptr.
   // defaults to 'en'.
-  Params *with_language(const char *language) {
-    fp->language = language;
+  Params *with_language(std::string language) {
+    this->language = language;
+    fp->language = this->language.c_str();
     return this;
   }
 


Test patch:
diff --git a/tests/params_export_test.py b/tests/params_export_test.py
index 7265f3f..7e6965e 100644
--- a/tests/params_export_test.py
+++ b/tests/params_export_test.py
@@ -86,3 +86,11 @@ def test_sampling_on_setattr_warning():
     with pytest.warns(DeprecationWarning, match=r"Setting 'beam_search' as an *"):
         ss = w.api.SamplingStrategies.from_enum(w.api.SAMPLING_BEAM_SEARCH)
         ss.beam_search = w.api.SamplingBeamSearchStrategy(2, 2)
+
+def test_set_language():
+    params = w.api.Params.from_enum(w.api.StrategyType.SAMPLING_GREEDY)
+    for lang in ["en", "de", "auto", ""]:
+        assert params.language != ""
+        params_with_lang = params.with_language(lang)
+        print(lang, params_with_lang.language)
+        assert params_with_lang.language == lang