Compare commits
No commits in common. "77e743482abc050f0489693cea3b97c5e41af9d5" and "b01f367a45a901ee0e80d27ba79334fe93e8b9cb" have entirely different histories.
77e743482a
...
b01f367a45
|
@ -1,15 +1,17 @@
|
|||
Python bindings for whisper.cpp
|
||||
===============================
|
||||
|
||||
<a href="https://www.buymeacoffee.com/lukeFxC" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
|
||||
|
||||
---
|
||||
`pip install git+https://git.brz9.dev/ed/whispercpp.py`
|
||||
`pip install git+https://github.com/stlukey/whispercpp.py`
|
||||
|
||||
```python
|
||||
from whispercpp import Whisper
|
||||
|
||||
w = Whisper('tiny')
|
||||
|
||||
result = w.transcribe("myfile.mp3", lang="en")
|
||||
result = w.transcribe("myfile.mp3")
|
||||
text = w.extract_text(result)
|
||||
```
|
||||
|
||||
|
|
|
@ -16,12 +16,13 @@ cimport numpy as cnp
|
|||
cdef int SAMPLE_RATE = 16000
|
||||
cdef char* TEST_FILE = 'test.wav'
|
||||
cdef char* DEFAULT_MODEL = 'tiny'
|
||||
cdef char* LANGUAGE = b'en'
|
||||
cdef int N_THREADS = os.cpu_count()
|
||||
|
||||
MODELS = {
|
||||
'ggml-tiny.bin': 'https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-tiny.bin',
|
||||
'ggml-base.bin': 'https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.bin',
|
||||
'ggml-small.bin': 'https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-small.bin',
|
||||
'ggml-small.bin': 'hhttps://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-small.bin',
|
||||
'ggml-medium.bin': 'https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-medium.bin',
|
||||
'ggml-large.bin': 'https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large.bin',
|
||||
}
|
||||
|
@ -67,14 +68,14 @@ cdef cnp.ndarray[cnp.float32_t, ndim=1, mode="c"] load_audio(bytes file, int sr
|
|||
|
||||
return frames
|
||||
|
||||
cdef whisper_full_params default_params(char* language) nogil:
|
||||
cdef whisper_full_params default_params() nogil:
|
||||
cdef whisper_full_params params = whisper_full_default_params(
|
||||
whisper_sampling_strategy.WHISPER_SAMPLING_GREEDY
|
||||
)
|
||||
params.print_realtime = True
|
||||
params.print_progress = True
|
||||
params.translate = False
|
||||
params.language = <const char *>language
|
||||
params.language = <const char *> LANGUAGE
|
||||
n_threads = N_THREADS
|
||||
return params
|
||||
|
||||
|
@ -95,13 +96,14 @@ cdef class Whisper:
|
|||
else:
|
||||
self.ctx = whisper_init_from_file(model_b)
|
||||
|
||||
self.params = default_params()
|
||||
whisper_print_system_info()
|
||||
|
||||
|
||||
def __dealloc__(self):
|
||||
whisper_free(self.ctx)
|
||||
|
||||
def transcribe(self, filename=TEST_FILE, lang="auto"):
|
||||
def transcribe(self, filename=TEST_FILE):
|
||||
print("Loading data..")
|
||||
if (type(filename) == np.ndarray) :
|
||||
temp = filename
|
||||
|
@ -113,14 +115,9 @@ cdef class Whisper:
|
|||
|
||||
|
||||
cdef cnp.ndarray[cnp.float32_t, ndim=1, mode="c"] frames = temp
|
||||
language_bytes = str(lang).encode("utf-8")
|
||||
cdef char* c_string = language_bytes # Convert bytes to char*
|
||||
|
||||
params = default_params(c_string)
|
||||
|
||||
print("Transcribing..")
|
||||
|
||||
return whisper_full(self.ctx, params, &frames[0], len(frames))
|
||||
return whisper_full(self.ctx, self.params, &frames[0], len(frames))
|
||||
|
||||
def extract_text(self, int res):
|
||||
print("Extracting text...")
|
||||
|
|
Loading…
Reference in New Issue