Download the PHP package codewithkyrian/whisper.php without Composer

On this page you can find all versions of the php package codewithkyrian/whisper.php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package whisper.php

whisper.php

A PHP binding for whisper.cpp, enabling high-performance automatic speech recognition and transcription.

Requirements

Platform Support

Currently, whisper.php supports the following platforms:

Note: Windows support is currently in development. Contributions and help are welcome to expand platform compatibility!

Features

Speech recognition can be complex, but it doesn't have to be. Whisper.php simplifies the process by providing:

Installation

Install the library using Composer:

Whisper.php requires the FFI extension to be enabled. In your php.ini configuration file, uncomment or add:

Quick Start

Low-Level API

The low-level API provides developers with granular control over the transcription process. It closely mimics the original C implementation, allowing for detailed configuration and manual segment processing:

Model Loading

Downloading and managing whisper models can be a complex process. Whisper.php simplifies this with the ModelLoader, a convenient utility that streamlines model acquisition and management.

The ModelLoader::loadModel() method accepts two key parameters:

  1. Model Name: Specify the model variant you want to use:
    • Supported base models: tiny, tiny.en, base, base.en, small, small.en, medium, medium.en, large, large.en
    • Note: Quantized models (q5, q8, etc.) are not supported by this utility
  2. Model Directory: Specify the local directory where models should be stored and searched

In the example above, it looks for ggml-tiny.en.bin in the __DIR__./models directory and if the model isn't found locally, it automatically downloads it from the official whisper.cpp huggingface repository

Libraries Loading

Whisper.php relies on platform-specific shared libraries, which are automatically downloaded the first time you initialize a model context. While this may cause a slight delay on the initial run, the process is one-time (unless you update the library via Composer). Once the libraries are cached, subsequent runs will perform as expected.

Audio Input

THe Whisper model expects a float array of sampled audio data at 16kHz. While tools like ffmpeg can generate this data, Whisper.php provides a built-in helper function to simplify the process for you.

The readAudio()helper function Supports multiple audio formats (MP3, WAV, OGG, M4A), automatically resamples to 16kHz and does these efficiently using libsndfile and libsamplerate

The low level approach is ideal for developers who need:

High-Level API

For those seeking a more straightforward experience, the high-level API offers a simpler more abstracted workflow:

The Whisper::fromPretrained() method simplifies the entire setup process with three key parameters:

  1. Model Name: Specify the whisper model variant (e.g., 'tiny.en', 'base', 'small.en')
  2. Base Directory: Specify where models should be stored and searched
  3. Transcription Parameters: Optionally customize transcription behavior

The high-level API is perfect for quick prototyping, simple projects, or when you want to minimize boilerplate code while maintaining the power of the underlying whisper.cpp technology.

Whisper Full Parameters

The WhisperFullParams offers a comprehensive and flexible configuration mechanism for fine-tuning the transcription process. It's designed with a fluent interface thus enabling method chaining and creating a clean, readable way to configure transcription parameters.

Language Detection

While the whisper model is remarkably good at automatic language detection, there are scenarios where manually specifying the language can improve accuracy:

Threading

Computational performance can be fine-tuned by adjusting the number of threads used during transcription:

More threads can speed up transcription on multi-core systems. For very short audio files however, more threads might introduce overhead. Experiment with thread counts to find the sweet spot for your specific use case and hardware configuration.

Segment Callback

In many real-world applications, you'll want to process transcription segments as they're generated, rather than waiting for the entire transcription to complete. You can achieve that by providing a callback to the full params object that accepts a SegmentData object.

Progress Callback

Provide a callback to the full params to get access to the transcription progress.

There are lots of configurations in the WhisperFullParams. Modern IDEs with robust PHP intellisense will reveal a comprehensive list of configuration methods as you type, offering real-time suggestions and documentation for each parameter. Simply start typing withXXX() after WhisperFullParams::default(), and your IDE will guide you through the available configuration options.

Exporting Outputs

Once you've generated your transcription segments, you'll often need to export them in various formats for different use cases. Whisper.php provides convenient helper methods to export transcription segments to the most popular and widely-used formats. The exported segments are derived from an array of SegmentData objects, each containing precise timestamp and text information.

Logging

Whisper.php provides flexible logging capabilities, fully compatible with PSR-3 standards, which means seamless integration with popular logging libraries like Monolog and Laravel's logging system.

By default, logging is disabled, but the library includes a built-in WhisperLogger that allows quick and easy logging:

Just make sure to call this setLogger method before initializing your WhisperContext.

For more advanced logging needs, whisper.php integrates perfectly with Monolog, the most popular PHP logging library:

OR with Laravel Application Logger

Contributing

Contributions are welcome! Especially for:

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Acknowledgements


All versions of whisper.php with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-ffi Version *
psr/log Version ^3.0
codewithkyrian/platform-package-installer Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package codewithkyrian/whisper.php contains the following files

Loading the files please wait ....