added buffer support
This commit is contained in:
parent
e2581c8aad
commit
a0337b36a1
16
setup.py
16
setup.py
|
@ -8,20 +8,20 @@ if sys.platform == 'darwin':
|
||||||
os.environ['CXXFLAGS'] = '-DGGML_USE_ACCELERATE -O3 -std=c++11'
|
os.environ['CXXFLAGS'] = '-DGGML_USE_ACCELERATE -O3 -std=c++11'
|
||||||
os.environ['LDFLAGS'] = '-framework Accelerate'
|
os.environ['LDFLAGS'] = '-framework Accelerate'
|
||||||
else:
|
else:
|
||||||
os.environ['CFLAGS'] = '-mavx -mavx2 -mfma -mf16c -O3 -std=gnu11'
|
os.environ['CFLAGS'] = '-mavx -mavx2 -mfma -mf16c -O3 /std:c++14'
|
||||||
os.environ['CXXFLAGS'] = '-mavx -mavx2 -mfma -mf16c -O3 -std=c++11'
|
os.environ['CXXFLAGS'] = '-mavx -mavx2 -mfma -mf16c -O3 /std:c++14'
|
||||||
|
|
||||||
ext_modules = [
|
ext_modules = [
|
||||||
Extension(
|
Extension(
|
||||||
name="whispercpp",
|
name="whispercpp",
|
||||||
sources=["whispercpp.pyx", "whisper.cpp/whisper.cpp"],
|
sources=["C:\\Users\\aidan\\Desktop\\Code\\projectMesa\\whispercpp.py\\whispercpp.pyx", "C:\\Users\\aidan\\Desktop\\Code\\projectMesa\\whispercpp.py\\whisper.cpp/whisper.cpp"],
|
||||||
language="c++",
|
language="c++",
|
||||||
extra_compile_args=["-std=c++11"],
|
extra_compile_args=["/std:c++14"],
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
ext_modules = cythonize(ext_modules)
|
ext_modules = cythonize(ext_modules)
|
||||||
|
|
||||||
whisper_clib = ('whisper_clib', {'sources': ['whisper.cpp/ggml.c']})
|
whisper_clib = ('whisper_clib', {'sources': ['C:\\Users\\aidan\\Desktop\\Code\\projectMesa\\whispercpp.py\\whisper.cpp/ggml.c']})
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='whispercpp',
|
name='whispercpp',
|
||||||
|
@ -30,8 +30,8 @@ setup(
|
||||||
author='Luke Southam',
|
author='Luke Southam',
|
||||||
author_email='luke@devthe.com',
|
author_email='luke@devthe.com',
|
||||||
libraries=[whisper_clib],
|
libraries=[whisper_clib],
|
||||||
ext_modules = cythonize("whispercpp.pyx"),
|
ext_modules=cythonize(ext_modules),
|
||||||
include_dirs = ['./whisper.cpp/', numpy.get_include()],
|
include_dirs=['C:\\Users\\aidan\\Desktop\\Code\\projectMesa\\whispercpp.py\\whisper.cpp', numpy.get_include()],
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'numpy',
|
'numpy',
|
||||||
'ffmpeg-python',
|
'ffmpeg-python',
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 1d716d6e34f3f4ba57bd9706a9258a0bdb008153
|
Subproject commit 0a2d1210bcb98978214bbf4e100922a413afd39d
|
File diff suppressed because it is too large
Load Diff
|
@ -71,7 +71,8 @@ cdef extern from "whisper.h" nogil:
|
||||||
whisper_encoder_begin_callback encoder_begin_callback
|
whisper_encoder_begin_callback encoder_begin_callback
|
||||||
void* encoder_begin_callback_user_data
|
void* encoder_begin_callback_user_data
|
||||||
whisper_full_params whisper_full_default_params(whisper_sampling_strategy)
|
whisper_full_params whisper_full_default_params(whisper_sampling_strategy)
|
||||||
cdef whisper_context* whisper_init(char*)
|
cdef whisper_context* whisper_init_from_file(char*)
|
||||||
|
cdef whisper_context* whisper_init_from_buffer(voidptr, int)
|
||||||
cdef void whisper_free(whisper_context*)
|
cdef void whisper_free(whisper_context*)
|
||||||
cdef int whisper_pcm_to_mel(whisper_context*, float*, int, int)
|
cdef int whisper_pcm_to_mel(whisper_context*, float*, int, int)
|
||||||
cdef int whisper_set_mel(whisper_context*, float*, int, int)
|
cdef int whisper_set_mel(whisper_context*, float*, int, int)
|
||||||
|
|
|
@ -16,7 +16,7 @@ cimport numpy as cnp
|
||||||
cdef int SAMPLE_RATE = 16000
|
cdef int SAMPLE_RATE = 16000
|
||||||
cdef char* TEST_FILE = 'test.wav'
|
cdef char* TEST_FILE = 'test.wav'
|
||||||
cdef char* DEFAULT_MODEL = 'tiny'
|
cdef char* DEFAULT_MODEL = 'tiny'
|
||||||
cdef char* LANGUAGE = b'fr'
|
cdef char* LANGUAGE = b'en'
|
||||||
cdef int N_THREADS = os.cpu_count()
|
cdef int N_THREADS = os.cpu_count()
|
||||||
|
|
||||||
MODELS = {
|
MODELS = {
|
||||||
|
@ -84,21 +84,37 @@ cdef class Whisper:
|
||||||
cdef whisper_context * ctx
|
cdef whisper_context * ctx
|
||||||
cdef whisper_full_params params
|
cdef whisper_full_params params
|
||||||
|
|
||||||
def __init__(self, model=DEFAULT_MODEL, pb=None):
|
def __init__(self, model=DEFAULT_MODEL, pb=None, buf=None):
|
||||||
model_fullname = f'ggml-{model}.bin'.encode('utf8')
|
|
||||||
|
model_fullname = f'ggml-{model}.bin'
|
||||||
download_model(model_fullname)
|
download_model(model_fullname)
|
||||||
model_path = Path(MODELS_DIR).joinpath(model_fullname)
|
model_path = Path(MODELS_DIR).joinpath(model_fullname)
|
||||||
cdef bytes model_b = str(model_path).encode('utf8')
|
cdef bytes model_b = str(model_path).encode('utf8')
|
||||||
self.ctx = whisper_init(model_b)
|
|
||||||
|
if buf is not None:
|
||||||
|
self.ctx = whisper_init_from_buffer(buf, buf.size)
|
||||||
|
else:
|
||||||
|
self.ctx = whisper_init_from_file(model_b)
|
||||||
|
|
||||||
self.params = default_params()
|
self.params = default_params()
|
||||||
whisper_print_system_info()
|
whisper_print_system_info()
|
||||||
|
|
||||||
|
|
||||||
def __dealloc__(self):
|
def __dealloc__(self):
|
||||||
whisper_free(self.ctx)
|
whisper_free(self.ctx)
|
||||||
|
|
||||||
def transcribe(self, filename=TEST_FILE):
|
def transcribe(self, filename=TEST_FILE):
|
||||||
print("Loading data..")
|
print("Loading data..")
|
||||||
cdef cnp.ndarray[cnp.float32_t, ndim=1, mode="c"] frames = load_audio(<bytes>filename)
|
if (type(filename) == np.ndarray) :
|
||||||
|
temp = filename
|
||||||
|
|
||||||
|
elif (type(filename) == str) :
|
||||||
|
temp = load_audio(<bytes>filename)
|
||||||
|
else :
|
||||||
|
temp = load_audio(<bytes>TEST_FILE)
|
||||||
|
|
||||||
|
|
||||||
|
cdef cnp.ndarray[cnp.float32_t, ndim=1, mode="c"] frames = temp
|
||||||
|
|
||||||
print("Transcribing..")
|
print("Transcribing..")
|
||||||
return whisper_full(self.ctx, self.params, &frames[0], len(frames))
|
return whisper_full(self.ctx, self.params, &frames[0], len(frames))
|
||||||
|
|
Loading…
Reference in New Issue