Package: whisper-cpp-pybind
whisper-cpp-pybind: python bindings for whisper.cppwhisper-cpp-pybind provides an interface for callingwhisper.cppin Python. And whisper.cpp provides accelerated inference forwhispermodels. This project provides both high-level and low-level API. The high-level API almost implement all the features of themain exampleof whisper.cppInstallationInstall form PyPIpipintallwhisper-cpp-pybindInstall Locallygitclone--recurse-submoduleshttps://github.com/sphantix/whisper-cpp-pybind.gitcdwhisper-cpp-python# Install with pippipinstall.Install with Hardware Accelerationwhisper.cpp supports multiple hardware for faster processing, so you can also install with the following command:OpenBLASMake sure you have installedopenblas:https://www.openblas.net/# Install with with haradware acceleration (OpenBLAS)pipinstall--config-settings="--build-option=--accelerate=openblas".cuBLASMake sure you have installedcudafor Nvidia cards:https://developer.nvidia.com/cuda-downloads# Install with with haradware acceleration (cuBLAS)pipinstall--config-settings="--build-option=--accelerate=cublas".CLBlastFor cards and integrated GPUs that support OpenCL, whisper.cpp can be largely offloaded to the GPU through CLBlast. This is especially useful for users with AMD APUs or low end devices for up to ~2x speedup.Make sure you have installedCLBlastfor your OS:https://github.com/CNugteren/CLBlast# Install with with haradware acceleration (CLBlast)pipinstall--config-settings="--build-option=--accelerate=clblast".CoreMLOn Apple Silicon devices, whisper.cpp can be executed on the Apple Neural Engine (ANE) via Core ML.Make sure you have installedCoreMLenvironment for your OS:https://github.com/apple/coremltools# Install with with haradware acceleration (CoreML)pipinstall--config-settings="--build-option=--accelerate=coreml".OpenVINOOn Intel devices which have x86 CPUs and Intel GPUs (integrated & discrete) whisper.cpp can be accelerated using OpenVINO.Make sure you have installedOpenVINOenvironment for your OS:https://github.com/openvinotoolkit/openvino# Install with with haradware acceleration (OpenVINO)pipinstall--config-settings="--build-option=--accelerate=openvino".UsageHigh-level APIThe high-level API provides two main interface through theWisperclass.Below is a simple example demonstrating how to use the high-level API to transcribe a wav file:fromwhisper_cppimportWhisperwhisper=Whisper("/../models/ggml-large.bin")whisper.transcribe("samples.wav",diarize=True)whisper.output(output_csv=True,output_jsn=True,output_lrc=True,output_srt=True,output_txt=True,output_vtt=True,log_score=True)Low-level APIAll functions provided bywhisper.hare translated to python interfaces.Below is an example to use low-level api to transcribe.fromctypesimport(c_float,)fromwhisper_cpp.whisper_cppimport(whisper_init_from_file,whisper_full_default_params,whisper_full_parallel,whisper_full_n_segments,whisper_full_get_segment_text,WHISPER_SAMPLING_GREEDY,)fromwhisper_cpp.utilsimportread_wavpcmf32=[]pcmf32s=[]ifnotread_wav("samples/samples.wav",pcmf32,pcmf32s,False):raiseRuntimeError("Failed to read WAV file!")whisper_ctx=whisper_init_from_file("../models/ggml-large.bin".encode("utf-8"))wparams=whisper_full_default_params(WHISPER_SAMPLING_GREEDY)pcmf32_array=(c_float*len(pcmf32))(*(iforiinpcmf32))whisper_full_parallel(ctx=whisper_ctx,params=wparams,samples=pcmf32_array,n_samples=len(pcmf32),n_processors=1)result=""n_segments=whisper_full_n_segments(whisper_ctx)foriinrange(n_segments):text=whisper_full_get_segment_text(whisper_ctx,i)result=result+text.decode('utf-8')print(result)DevelopmentThis package is under active development and any contributions will be welcomed.Licensewhisper-cpp-pybind is released under the MIT License.