topai-faster-whisper


Nametopai-faster-whisper JSON
Version 1.0.4.post4 PyPI version JSON
download
home_pagehttps://github.com/SYSTRAN/faster-whisper
SummaryFaster Whisper transcription with CTranslate2
upload_time2024-10-17 09:28:10
maintainerNone
docs_urlNone
authorGuillaume Klein
requires_python>=3.8
licenseMIT
keywords openai whisper speech ctranslate2 inference quantization transformer
VCS
bugtrack_url
requirements ctranslate2 huggingface_hub tokenizers onnxruntime pyannote-audio torch torchaudio tqdm
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![CI](https://github.com/SYSTRAN/faster-whisper/workflows/CI/badge.svg)](https://github.com/SYSTRAN/faster-whisper/actions?query=workflow%3ACI) [![PyPI version](https://badge.fury.io/py/faster-whisper.svg)](https://badge.fury.io/py/faster-whisper)

# Faster Whisper transcription with CTranslate2

**faster-whisper** is a reimplementation of OpenAI's Whisper model using [CTranslate2](https://github.com/OpenNMT/CTranslate2/), which is a fast inference engine for Transformer models.

This implementation is up to 4 times faster than [openai/whisper](https://github.com/openai/whisper) for the same accuracy while using less memory. The efficiency can be further improved with 8-bit quantization on both CPU and GPU.

## Benchmark

### Whisper

For reference, here's the time and memory usage that are required to transcribe [**13 minutes**](https://www.youtube.com/watch?v=0u7tTptBo9I) of audio using different implementations:

* [openai/whisper](https://github.com/openai/whisper)@[6dea21fd](https://github.com/openai/whisper/commit/6dea21fd7f7253bfe450f1e2512a0fe47ee2d258)
* [whisper.cpp](https://github.com/ggerganov/whisper.cpp)@[3b010f9](https://github.com/ggerganov/whisper.cpp/commit/3b010f9bed9a6068609e9faf52383aea792b0362)
* [faster-whisper](https://github.com/SYSTRAN/faster-whisper)@[cce6b53e](https://github.com/SYSTRAN/faster-whisper/commit/cce6b53e4554f71172dad188c45f10fb100f6e3e)

### Large-v2 model on GPU

| Implementation | Precision | Beam size | Time | Max. GPU memory | Max. CPU memory |
| --- | --- | --- | --- | --- | --- |
| openai/whisper | fp16 | 5 | 4m30s | 11325MB | 9439MB |
| faster-whisper | fp16 | 5 | 54s | 4755MB | 3244MB |
| faster-whisper | int8 | 5 | 59s | 3091MB | 3117MB |

*Executed with CUDA 11.7.1 on a NVIDIA Tesla V100S.*

### Small model on CPU

| Implementation | Precision | Beam size | Time | Max. memory |
| --- | --- | --- | --- | --- |
| openai/whisper | fp32 | 5 | 10m31s | 3101MB |
| whisper.cpp | fp32 | 5 | 17m42s | 1581MB |
| whisper.cpp | fp16 | 5 | 12m39s | 873MB |
| faster-whisper | fp32 | 5 | 2m44s | 1675MB |
| faster-whisper | int8 | 5 | 2m04s | 995MB |

*Executed with 8 threads on a Intel(R) Xeon(R) Gold 6226R.*


### Distil-whisper

| Implementation | Precision | Beam size | Time | Gigaspeech WER |
| --- | --- | --- | --- | --- |
| distil-whisper/distil-large-v2 | fp16 | 4 |- | 10.36 |
| [faster-distil-large-v2](https://huggingface.co/Systran/faster-distil-whisper-large-v2) | fp16 | 5 | - | 10.28 |
| distil-whisper/distil-medium.en | fp16 | 4 | - | 11.21 |
| [faster-distil-medium.en](https://huggingface.co/Systran/faster-distil-whisper-medium.en) | fp16 | 5 | - | 11.21 |

*Executed with CUDA 11.4 on a NVIDIA 3090.*

<details>
<summary>testing details (click to expand)</summary>

For `distil-whisper/distil-large-v2`, the WER is tested with code sample from [link](https://huggingface.co/distil-whisper/distil-large-v2#evaluation). for `faster-distil-whisper`, the WER is tested with setting:
```python
from faster_whisper import WhisperModel

model_size = "distil-large-v2"
# model_size = "distil-medium.en"
# Run on GPU with FP16
model = WhisperModel(model_size, device="cuda", compute_type="float16")
segments, info = model.transcribe("audio.mp3", beam_size=5, language="en")
```
</details>

## Requirements

* Python 3.8 or greater


### GPU

GPU execution requires the following NVIDIA libraries to be installed:

* [cuBLAS for CUDA 12](https://developer.nvidia.com/cublas)
* [cuDNN 8 for CUDA 12](https://developer.nvidia.com/cudnn)

**Note**: Latest versions of `ctranslate2` support CUDA 12 only. For CUDA 11, the current workaround is downgrading to the `3.24.0` version of `ctranslate2` (This can be done with `pip install --force-reinstall ctranslate2==3.24.0` or specifying the version in a `requirements.txt`).

There are multiple ways to install the NVIDIA libraries mentioned above. The recommended way is described in the official NVIDIA documentation, but we also suggest other installation methods below. 

<details>
<summary>Other installation methods (click to expand)</summary>


**Note:** For all these methods below, keep in mind the above note regarding CUDA versions. Depending on your setup, you may need to install the _CUDA 11_ versions of libraries that correspond to the CUDA 12 libraries listed in the instructions below.

#### Use Docker

The libraries (cuBLAS, cuDNN) are installed in these official NVIDIA CUDA Docker images: `nvidia/cuda:12.0.0-runtime-ubuntu20.04` or `nvidia/cuda:12.0.0-runtime-ubuntu22.04`.

#### Install with `pip` (Linux only)

On Linux these libraries can be installed with `pip`. Note that `LD_LIBRARY_PATH` must be set before launching Python.

```bash
pip install nvidia-cublas-cu12 nvidia-cudnn-cu12

export LD_LIBRARY_PATH=`python3 -c 'import os; import nvidia.cublas.lib; import nvidia.cudnn.lib; print(os.path.dirname(nvidia.cublas.lib.__file__) + ":" + os.path.dirname(nvidia.cudnn.lib.__file__))'`
```

**Note**: Version 9+ of `nvidia-cudnn-cu12` appears to cause issues due its reliance on cuDNN 9 (Faster-Whisper does not currently support cuDNN 9). Ensure your version of the Python package is for cuDNN 8.

#### Download the libraries from Purfview's repository (Windows & Linux)

Purfview's [whisper-standalone-win](https://github.com/Purfview/whisper-standalone-win) provides the required NVIDIA libraries for Windows & Linux in a [single archive](https://github.com/Purfview/whisper-standalone-win/releases/tag/libs). Decompress the archive and place the libraries in a directory included in the `PATH`.

</details>

## Installation

The module can be installed from [PyPI](https://pypi.org/project/faster-whisper/):

```bash
pip install faster-whisper
```

<details>
<summary>Other installation methods (click to expand)</summary>

### Install the master branch

```bash
pip install --force-reinstall "faster-whisper @ https://github.com/SYSTRAN/faster-whisper/archive/refs/heads/master.tar.gz"
```

### Install a specific commit

```bash
pip install --force-reinstall "faster-whisper @ https://github.com/SYSTRAN/faster-whisper/archive/a4f1cc8f11433e454c3934442b5e1a4ed5e865c3.tar.gz"
```

</details>

## Usage

### Faster-whisper

```python
from faster_whisper import WhisperModel

model_size = "large-v3"

# Run on GPU with FP16
model = WhisperModel(model_size, device="cuda", compute_type="float16")

# or run on GPU with INT8
# model = WhisperModel(model_size, device="cuda", compute_type="int8_float16")
# or run on CPU with INT8
# model = WhisperModel(model_size, device="cpu", compute_type="int8")

segments, info = model.transcribe("audio.mp3", beam_size=5)

print("Detected language '%s' with probability %f" % (info.language, info.language_probability))

for segment in segments:
    print("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
```

**Warning:** `segments` is a *generator* so the transcription only starts when you iterate over it. The transcription can be run to completion by gathering the segments in a list or a `for` loop:

```python
segments, _ = model.transcribe("audio.mp3")
segments = list(segments)  # The transcription will actually run here.
```

### multi-segment language detection

To directly use the model for improved language detection, the following code snippet can be used:

```python
from faster_whisper import WhisperModel
model = WhisperModel("medium", device="cuda", compute_type="float16")
language_info = model.detect_language_multi_segment("audio.mp3")
```

### Batched faster-whisper


The batched version of faster-whisper is inspired by [whisper-x](https://github.com/m-bain/whisperX) licensed under the BSD-2 Clause license and integrates its VAD model to this library. We modify this implementation and also replaced the feature extraction with a faster torch-based implementation. Batched version improves the speed upto 10-12x compared to openAI implementation and 3-4x compared to the sequential faster_whisper version. It works by transcribing semantically meaningful audio chunks as batches leading to faster inference. 

The following code snippet illustrates how to run inference with batched version on an example audio file. Please also refer to the test scripts of batched faster whisper.

```python
from faster_whisper import WhisperModel, BatchedInferencePipeline

model = WhisperModel("medium", device="cuda", compute_type="float16")
batched_model = BatchedInferencePipeline(model=model)
segments, info = batched_model.transcribe("audio.mp3", batch_size=16)

for segment in segments:
    print("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
```

### Faster Distil-Whisper

The Distil-Whisper checkpoints are compatible with the Faster-Whisper package. In particular, the latest [distil-large-v3](https://huggingface.co/distil-whisper/distil-large-v3)
checkpoint is intrinsically designed to work with the Faster-Whisper transcription algorithm. The following code snippet 
demonstrates how to run inference with distil-large-v3 on a specified audio file:

```python
from faster_whisper import WhisperModel

model_size = "distil-large-v3"

model = WhisperModel(model_size, device="cuda", compute_type="float16")
segments, info = model.transcribe("audio.mp3", beam_size=5, language="en", condition_on_previous_text=False)

for segment in segments:
    print("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
```

For more information about the distil-large-v3 model, refer to the original [model card](https://huggingface.co/distil-whisper/distil-large-v3).

### Word-level timestamps

```python
segments, _ = model.transcribe("audio.mp3", word_timestamps=True)

for segment in segments:
    for word in segment.words:
        print("[%.2fs -> %.2fs] %s" % (word.start, word.end, word.word))
```

### VAD filter

The library integrates the [Silero VAD](https://github.com/snakers4/silero-vad) model to filter out parts of the audio without speech:

```python
segments, _ = model.transcribe("audio.mp3", vad_filter=True)
```

The default behavior is conservative and only removes silence longer than 2 seconds. See the available VAD parameters and default values in the [source code](https://github.com/SYSTRAN/faster-whisper/blob/master/faster_whisper/vad.py). They can be customized with the dictionary argument `vad_parameters`:

```python
segments, _ = model.transcribe(
    "audio.mp3",
    vad_filter=True,
    vad_parameters=dict(min_silence_duration_ms=500),
)
```

### Logging

The library logging level can be configured like this:

```python
import logging

logging.basicConfig()
logging.getLogger("faster_whisper").setLevel(logging.DEBUG)
```

### Going further

See more model and transcription options in the [`WhisperModel`](https://github.com/SYSTRAN/faster-whisper/blob/master/faster_whisper/transcribe.py) class implementation.

## Community integrations

Here is a non exhaustive list of open-source projects using faster-whisper. Feel free to add your project to the list!


* [faster-whisper-server](https://github.com/fedirz/faster-whisper-server) is an OpenAI compatible server using `faster-whisper`. It's easily deployable with Docker, works with OpenAI SDKs/CLI, supports streaming, and live transcription.
* [WhisperX](https://github.com/m-bain/whisperX) is an award-winning Python library that offers speaker diarization and accurate word-level timestamps using wav2vec2 alignment
* [whisper-ctranslate2](https://github.com/Softcatala/whisper-ctranslate2) is a command line client based on faster-whisper and compatible with the original client from openai/whisper.
* [whisper-diarize](https://github.com/MahmoudAshraf97/whisper-diarization) is a speaker diarization tool that is based on faster-whisper and NVIDIA NeMo.
* [whisper-standalone-win](https://github.com/Purfview/whisper-standalone-win) Standalone CLI executables of faster-whisper for Windows, Linux & macOS. 
* [asr-sd-pipeline](https://github.com/hedrergudene/asr-sd-pipeline) provides a scalable, modular, end to end multi-speaker speech to text solution implemented using AzureML pipelines.
* [Open-Lyrics](https://github.com/zh-plus/Open-Lyrics) is a Python library that transcribes voice files using faster-whisper, and translates/polishes the resulting text into `.lrc` files in the desired language using OpenAI-GPT.
* [wscribe](https://github.com/geekodour/wscribe) is a flexible transcript generation tool supporting faster-whisper, it can export word level transcript and the exported transcript then can be edited with [wscribe-editor](https://github.com/geekodour/wscribe-editor)
* [aTrain](https://github.com/BANDAS-Center/aTrain) is a graphical user interface implementation of faster-whisper developed at the BANDAS-Center at the University of Graz for transcription and diarization in Windows ([Windows Store App](https://apps.microsoft.com/detail/atrain/9N15Q44SZNS2)) and Linux.
* [Whisper-Streaming](https://github.com/ufal/whisper_streaming) implements real-time mode for offline Whisper-like speech-to-text models with faster-whisper as the most recommended back-end. It implements a streaming policy with self-adaptive latency based on the actual source complexity, and demonstrates the state of the art.
* [WhisperLive](https://github.com/collabora/WhisperLive) is a nearly-live implementation of OpenAI's Whisper which uses faster-whisper as the backend to transcribe audio in real-time.
* [Faster-Whisper-Transcriber](https://github.com/BBC-Esq/ctranslate2-faster-whisper-transcriber) is a simple but reliable voice transcriber that provides a user-friendly interface.

## Model conversion

When loading a model from its size such as `WhisperModel("large-v3")`, the corresponding CTranslate2 model is automatically downloaded from the [Hugging Face Hub](https://huggingface.co/Systran).

We also provide a script to convert any Whisper models compatible with the Transformers library. They could be the original OpenAI models or user fine-tuned models.

For example the command below converts the [original "large-v3" Whisper model](https://huggingface.co/openai/whisper-large-v3) and saves the weights in FP16:

```bash
pip install transformers[torch]>=4.23

ct2-transformers-converter --model openai/whisper-large-v3 --output_dir whisper-large-v3-ct2
--copy_files tokenizer.json preprocessor_config.json --quantization float16
```

* The option `--model` accepts a model name on the Hub or a path to a model directory.
* If the option `--copy_files tokenizer.json` is not used, the tokenizer configuration is automatically downloaded when the model is loaded later.

Models can also be converted from the code. See the [conversion API](https://opennmt.net/CTranslate2/python/ctranslate2.converters.TransformersConverter.html).

### Load a converted model

1. Directly load the model from a local directory:
```python
model = faster_whisper.WhisperModel("whisper-large-v3-ct2")
```

2. [Upload your model to the Hugging Face Hub](https://huggingface.co/docs/transformers/model_sharing#upload-with-the-web-interface) and load it from its name:
```python
model = faster_whisper.WhisperModel("username/whisper-large-v3-ct2")
```

## Comparing performance against other implementations

If you are comparing the performance against other Whisper implementations, you should make sure to run the comparison with similar settings. In particular:

* Verify that the same transcription options are used, especially the same beam size. For example in openai/whisper, `model.transcribe` uses a default beam size of 1 but here we use a default beam size of 5.
* When running on CPU, make sure to set the same number of threads. Many frameworks will read the environment variable `OMP_NUM_THREADS`, which can be set when running your script:

```bash
OMP_NUM_THREADS=4 python3 my_script.py
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/SYSTRAN/faster-whisper",
    "name": "topai-faster-whisper",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "openai whisper speech ctranslate2 inference quantization transformer",
    "author": "Guillaume Klein",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/4c/ac/78e4ac0a6010b1009d0c5cc1a6e786995406d770260a22be77fad2927b0e/topai_faster_whisper-1.0.4.post4.tar.gz",
    "platform": null,
    "description": "[![CI](https://github.com/SYSTRAN/faster-whisper/workflows/CI/badge.svg)](https://github.com/SYSTRAN/faster-whisper/actions?query=workflow%3ACI) [![PyPI version](https://badge.fury.io/py/faster-whisper.svg)](https://badge.fury.io/py/faster-whisper)\r\n\r\n# Faster Whisper transcription with CTranslate2\r\n\r\n**faster-whisper** is a reimplementation of OpenAI's Whisper model using [CTranslate2](https://github.com/OpenNMT/CTranslate2/), which is a fast inference engine for Transformer models.\r\n\r\nThis implementation is up to 4 times faster than [openai/whisper](https://github.com/openai/whisper) for the same accuracy while using less memory. The efficiency can be further improved with 8-bit quantization on both CPU and GPU.\r\n\r\n## Benchmark\r\n\r\n### Whisper\r\n\r\nFor reference, here's the time and memory usage that are required to transcribe [**13 minutes**](https://www.youtube.com/watch?v=0u7tTptBo9I) of audio using different implementations:\r\n\r\n* [openai/whisper](https://github.com/openai/whisper)@[6dea21fd](https://github.com/openai/whisper/commit/6dea21fd7f7253bfe450f1e2512a0fe47ee2d258)\r\n* [whisper.cpp](https://github.com/ggerganov/whisper.cpp)@[3b010f9](https://github.com/ggerganov/whisper.cpp/commit/3b010f9bed9a6068609e9faf52383aea792b0362)\r\n* [faster-whisper](https://github.com/SYSTRAN/faster-whisper)@[cce6b53e](https://github.com/SYSTRAN/faster-whisper/commit/cce6b53e4554f71172dad188c45f10fb100f6e3e)\r\n\r\n### Large-v2 model on GPU\r\n\r\n| Implementation | Precision | Beam size | Time | Max. GPU memory | Max. CPU memory |\r\n| --- | --- | --- | --- | --- | --- |\r\n| openai/whisper | fp16 | 5 | 4m30s | 11325MB | 9439MB |\r\n| faster-whisper | fp16 | 5 | 54s | 4755MB | 3244MB |\r\n| faster-whisper | int8 | 5 | 59s | 3091MB | 3117MB |\r\n\r\n*Executed with CUDA 11.7.1 on a NVIDIA Tesla V100S.*\r\n\r\n### Small model on CPU\r\n\r\n| Implementation | Precision | Beam size | Time | Max. memory |\r\n| --- | --- | --- | --- | --- |\r\n| openai/whisper | fp32 | 5 | 10m31s | 3101MB |\r\n| whisper.cpp | fp32 | 5 | 17m42s | 1581MB |\r\n| whisper.cpp | fp16 | 5 | 12m39s | 873MB |\r\n| faster-whisper | fp32 | 5 | 2m44s | 1675MB |\r\n| faster-whisper | int8 | 5 | 2m04s | 995MB |\r\n\r\n*Executed with 8 threads on a Intel(R) Xeon(R) Gold 6226R.*\r\n\r\n\r\n### Distil-whisper\r\n\r\n| Implementation | Precision | Beam size | Time | Gigaspeech WER |\r\n| --- | --- | --- | --- | --- |\r\n| distil-whisper/distil-large-v2 | fp16 | 4 |- | 10.36 |\r\n| [faster-distil-large-v2](https://huggingface.co/Systran/faster-distil-whisper-large-v2) | fp16 | 5 | - | 10.28 |\r\n| distil-whisper/distil-medium.en | fp16 | 4 | - | 11.21 |\r\n| [faster-distil-medium.en](https://huggingface.co/Systran/faster-distil-whisper-medium.en) | fp16 | 5 | - | 11.21 |\r\n\r\n*Executed with CUDA 11.4 on a NVIDIA 3090.*\r\n\r\n<details>\r\n<summary>testing details (click to expand)</summary>\r\n\r\nFor `distil-whisper/distil-large-v2`, the WER is tested with code sample from [link](https://huggingface.co/distil-whisper/distil-large-v2#evaluation). for `faster-distil-whisper`, the WER is tested with setting:\r\n```python\r\nfrom faster_whisper import WhisperModel\r\n\r\nmodel_size = \"distil-large-v2\"\r\n# model_size = \"distil-medium.en\"\r\n# Run on GPU with FP16\r\nmodel = WhisperModel(model_size, device=\"cuda\", compute_type=\"float16\")\r\nsegments, info = model.transcribe(\"audio.mp3\", beam_size=5, language=\"en\")\r\n```\r\n</details>\r\n\r\n## Requirements\r\n\r\n* Python 3.8 or greater\r\n\r\n\r\n### GPU\r\n\r\nGPU execution requires the following NVIDIA libraries to be installed:\r\n\r\n* [cuBLAS for CUDA 12](https://developer.nvidia.com/cublas)\r\n* [cuDNN 8 for CUDA 12](https://developer.nvidia.com/cudnn)\r\n\r\n**Note**: Latest versions of `ctranslate2` support CUDA 12 only. For CUDA 11, the current workaround is downgrading to the `3.24.0` version of `ctranslate2` (This can be done with `pip install --force-reinstall ctranslate2==3.24.0` or specifying the version in a `requirements.txt`).\r\n\r\nThere are multiple ways to install the NVIDIA libraries mentioned above. The recommended way is described in the official NVIDIA documentation, but we also suggest other installation methods below. \r\n\r\n<details>\r\n<summary>Other installation methods (click to expand)</summary>\r\n\r\n\r\n**Note:** For all these methods below, keep in mind the above note regarding CUDA versions. Depending on your setup, you may need to install the _CUDA 11_ versions of libraries that correspond to the CUDA 12 libraries listed in the instructions below.\r\n\r\n#### Use Docker\r\n\r\nThe libraries (cuBLAS, cuDNN) are installed in these official NVIDIA CUDA Docker images: `nvidia/cuda:12.0.0-runtime-ubuntu20.04` or `nvidia/cuda:12.0.0-runtime-ubuntu22.04`.\r\n\r\n#### Install with `pip` (Linux only)\r\n\r\nOn Linux these libraries can be installed with `pip`. Note that `LD_LIBRARY_PATH` must be set before launching Python.\r\n\r\n```bash\r\npip install nvidia-cublas-cu12 nvidia-cudnn-cu12\r\n\r\nexport LD_LIBRARY_PATH=`python3 -c 'import os; import nvidia.cublas.lib; import nvidia.cudnn.lib; print(os.path.dirname(nvidia.cublas.lib.__file__) + \":\" + os.path.dirname(nvidia.cudnn.lib.__file__))'`\r\n```\r\n\r\n**Note**: Version 9+ of `nvidia-cudnn-cu12` appears to cause issues due its reliance on cuDNN 9 (Faster-Whisper does not currently support cuDNN 9). Ensure your version of the Python package is for cuDNN 8.\r\n\r\n#### Download the libraries from Purfview's repository (Windows & Linux)\r\n\r\nPurfview's [whisper-standalone-win](https://github.com/Purfview/whisper-standalone-win) provides the required NVIDIA libraries for Windows & Linux in a [single archive](https://github.com/Purfview/whisper-standalone-win/releases/tag/libs). Decompress the archive and place the libraries in a directory included in the `PATH`.\r\n\r\n</details>\r\n\r\n## Installation\r\n\r\nThe module can be installed from [PyPI](https://pypi.org/project/faster-whisper/):\r\n\r\n```bash\r\npip install faster-whisper\r\n```\r\n\r\n<details>\r\n<summary>Other installation methods (click to expand)</summary>\r\n\r\n### Install the master branch\r\n\r\n```bash\r\npip install --force-reinstall \"faster-whisper @ https://github.com/SYSTRAN/faster-whisper/archive/refs/heads/master.tar.gz\"\r\n```\r\n\r\n### Install a specific commit\r\n\r\n```bash\r\npip install --force-reinstall \"faster-whisper @ https://github.com/SYSTRAN/faster-whisper/archive/a4f1cc8f11433e454c3934442b5e1a4ed5e865c3.tar.gz\"\r\n```\r\n\r\n</details>\r\n\r\n## Usage\r\n\r\n### Faster-whisper\r\n\r\n```python\r\nfrom faster_whisper import WhisperModel\r\n\r\nmodel_size = \"large-v3\"\r\n\r\n# Run on GPU with FP16\r\nmodel = WhisperModel(model_size, device=\"cuda\", compute_type=\"float16\")\r\n\r\n# or run on GPU with INT8\r\n# model = WhisperModel(model_size, device=\"cuda\", compute_type=\"int8_float16\")\r\n# or run on CPU with INT8\r\n# model = WhisperModel(model_size, device=\"cpu\", compute_type=\"int8\")\r\n\r\nsegments, info = model.transcribe(\"audio.mp3\", beam_size=5)\r\n\r\nprint(\"Detected language '%s' with probability %f\" % (info.language, info.language_probability))\r\n\r\nfor segment in segments:\r\n    print(\"[%.2fs -> %.2fs] %s\" % (segment.start, segment.end, segment.text))\r\n```\r\n\r\n**Warning:** `segments` is a *generator* so the transcription only starts when you iterate over it. The transcription can be run to completion by gathering the segments in a list or a `for` loop:\r\n\r\n```python\r\nsegments, _ = model.transcribe(\"audio.mp3\")\r\nsegments = list(segments)  # The transcription will actually run here.\r\n```\r\n\r\n### multi-segment language detection\r\n\r\nTo directly use the model for improved language detection, the following code snippet can be used:\r\n\r\n```python\r\nfrom faster_whisper import WhisperModel\r\nmodel = WhisperModel(\"medium\", device=\"cuda\", compute_type=\"float16\")\r\nlanguage_info = model.detect_language_multi_segment(\"audio.mp3\")\r\n```\r\n\r\n### Batched faster-whisper\r\n\r\n\r\nThe batched version of faster-whisper is inspired by [whisper-x](https://github.com/m-bain/whisperX) licensed under the BSD-2 Clause license and integrates its VAD model to this library. We modify this implementation and also replaced the feature extraction with a faster torch-based implementation. Batched version improves the speed upto 10-12x compared to openAI implementation and 3-4x compared to the sequential faster_whisper version. It works by transcribing semantically meaningful audio chunks as batches leading to faster inference. \r\n\r\nThe following code snippet illustrates how to run inference with batched version on an example audio file. Please also refer to the test scripts of batched faster whisper.\r\n\r\n```python\r\nfrom faster_whisper import WhisperModel, BatchedInferencePipeline\r\n\r\nmodel = WhisperModel(\"medium\", device=\"cuda\", compute_type=\"float16\")\r\nbatched_model = BatchedInferencePipeline(model=model)\r\nsegments, info = batched_model.transcribe(\"audio.mp3\", batch_size=16)\r\n\r\nfor segment in segments:\r\n    print(\"[%.2fs -> %.2fs] %s\" % (segment.start, segment.end, segment.text))\r\n```\r\n\r\n### Faster Distil-Whisper\r\n\r\nThe Distil-Whisper checkpoints are compatible with the Faster-Whisper package. In particular, the latest [distil-large-v3](https://huggingface.co/distil-whisper/distil-large-v3)\r\ncheckpoint is intrinsically designed to work with the Faster-Whisper transcription algorithm. The following code snippet \r\ndemonstrates how to run inference with distil-large-v3 on a specified audio file:\r\n\r\n```python\r\nfrom faster_whisper import WhisperModel\r\n\r\nmodel_size = \"distil-large-v3\"\r\n\r\nmodel = WhisperModel(model_size, device=\"cuda\", compute_type=\"float16\")\r\nsegments, info = model.transcribe(\"audio.mp3\", beam_size=5, language=\"en\", condition_on_previous_text=False)\r\n\r\nfor segment in segments:\r\n    print(\"[%.2fs -> %.2fs] %s\" % (segment.start, segment.end, segment.text))\r\n```\r\n\r\nFor more information about the distil-large-v3 model, refer to the original [model card](https://huggingface.co/distil-whisper/distil-large-v3).\r\n\r\n### Word-level timestamps\r\n\r\n```python\r\nsegments, _ = model.transcribe(\"audio.mp3\", word_timestamps=True)\r\n\r\nfor segment in segments:\r\n    for word in segment.words:\r\n        print(\"[%.2fs -> %.2fs] %s\" % (word.start, word.end, word.word))\r\n```\r\n\r\n### VAD filter\r\n\r\nThe library integrates the [Silero VAD](https://github.com/snakers4/silero-vad) model to filter out parts of the audio without speech:\r\n\r\n```python\r\nsegments, _ = model.transcribe(\"audio.mp3\", vad_filter=True)\r\n```\r\n\r\nThe default behavior is conservative and only removes silence longer than 2 seconds. See the available VAD parameters and default values in the [source code](https://github.com/SYSTRAN/faster-whisper/blob/master/faster_whisper/vad.py). They can be customized with the dictionary argument `vad_parameters`:\r\n\r\n```python\r\nsegments, _ = model.transcribe(\r\n    \"audio.mp3\",\r\n    vad_filter=True,\r\n    vad_parameters=dict(min_silence_duration_ms=500),\r\n)\r\n```\r\n\r\n### Logging\r\n\r\nThe library logging level can be configured like this:\r\n\r\n```python\r\nimport logging\r\n\r\nlogging.basicConfig()\r\nlogging.getLogger(\"faster_whisper\").setLevel(logging.DEBUG)\r\n```\r\n\r\n### Going further\r\n\r\nSee more model and transcription options in the [`WhisperModel`](https://github.com/SYSTRAN/faster-whisper/blob/master/faster_whisper/transcribe.py) class implementation.\r\n\r\n## Community integrations\r\n\r\nHere is a non exhaustive list of open-source projects using faster-whisper. Feel free to add your project to the list!\r\n\r\n\r\n* [faster-whisper-server](https://github.com/fedirz/faster-whisper-server) is an OpenAI compatible server using `faster-whisper`. It's easily deployable with Docker, works with OpenAI SDKs/CLI, supports streaming, and live transcription.\r\n* [WhisperX](https://github.com/m-bain/whisperX) is an award-winning Python library that offers speaker diarization and accurate word-level timestamps using wav2vec2 alignment\r\n* [whisper-ctranslate2](https://github.com/Softcatala/whisper-ctranslate2) is a command line client based on faster-whisper and compatible with the original client from openai/whisper.\r\n* [whisper-diarize](https://github.com/MahmoudAshraf97/whisper-diarization) is a speaker diarization tool that is based on faster-whisper and NVIDIA NeMo.\r\n* [whisper-standalone-win](https://github.com/Purfview/whisper-standalone-win) Standalone CLI executables of faster-whisper for Windows, Linux & macOS. \r\n* [asr-sd-pipeline](https://github.com/hedrergudene/asr-sd-pipeline) provides a scalable, modular, end to end multi-speaker speech to text solution implemented using AzureML pipelines.\r\n* [Open-Lyrics](https://github.com/zh-plus/Open-Lyrics) is a Python library that transcribes voice files using faster-whisper, and translates/polishes the resulting text into `.lrc` files in the desired language using OpenAI-GPT.\r\n* [wscribe](https://github.com/geekodour/wscribe) is a flexible transcript generation tool supporting faster-whisper, it can export word level transcript and the exported transcript then can be edited with [wscribe-editor](https://github.com/geekodour/wscribe-editor)\r\n* [aTrain](https://github.com/BANDAS-Center/aTrain) is a graphical user interface implementation of faster-whisper developed at the BANDAS-Center at the University of Graz for transcription and diarization in Windows ([Windows Store App](https://apps.microsoft.com/detail/atrain/9N15Q44SZNS2)) and Linux.\r\n* [Whisper-Streaming](https://github.com/ufal/whisper_streaming) implements real-time mode for offline Whisper-like speech-to-text models with faster-whisper as the most recommended back-end. It implements a streaming policy with self-adaptive latency based on the actual source complexity, and demonstrates the state of the art.\r\n* [WhisperLive](https://github.com/collabora/WhisperLive) is a nearly-live implementation of OpenAI's Whisper which uses faster-whisper as the backend to transcribe audio in real-time.\r\n* [Faster-Whisper-Transcriber](https://github.com/BBC-Esq/ctranslate2-faster-whisper-transcriber) is a simple but reliable voice transcriber that provides a user-friendly interface.\r\n\r\n## Model conversion\r\n\r\nWhen loading a model from its size such as `WhisperModel(\"large-v3\")`, the corresponding CTranslate2 model is automatically downloaded from the [Hugging Face Hub](https://huggingface.co/Systran).\r\n\r\nWe also provide a script to convert any Whisper models compatible with the Transformers library. They could be the original OpenAI models or user fine-tuned models.\r\n\r\nFor example the command below converts the [original \"large-v3\" Whisper model](https://huggingface.co/openai/whisper-large-v3) and saves the weights in FP16:\r\n\r\n```bash\r\npip install transformers[torch]>=4.23\r\n\r\nct2-transformers-converter --model openai/whisper-large-v3 --output_dir whisper-large-v3-ct2\r\n--copy_files tokenizer.json preprocessor_config.json --quantization float16\r\n```\r\n\r\n* The option `--model` accepts a model name on the Hub or a path to a model directory.\r\n* If the option `--copy_files tokenizer.json` is not used, the tokenizer configuration is automatically downloaded when the model is loaded later.\r\n\r\nModels can also be converted from the code. See the [conversion API](https://opennmt.net/CTranslate2/python/ctranslate2.converters.TransformersConverter.html).\r\n\r\n### Load a converted model\r\n\r\n1. Directly load the model from a local directory:\r\n```python\r\nmodel = faster_whisper.WhisperModel(\"whisper-large-v3-ct2\")\r\n```\r\n\r\n2. [Upload your model to the Hugging Face Hub](https://huggingface.co/docs/transformers/model_sharing#upload-with-the-web-interface) and load it from its name:\r\n```python\r\nmodel = faster_whisper.WhisperModel(\"username/whisper-large-v3-ct2\")\r\n```\r\n\r\n## Comparing performance against other implementations\r\n\r\nIf you are comparing the performance against other Whisper implementations, you should make sure to run the comparison with similar settings. In particular:\r\n\r\n* Verify that the same transcription options are used, especially the same beam size. For example in openai/whisper, `model.transcribe` uses a default beam size of 1 but here we use a default beam size of 5.\r\n* When running on CPU, make sure to set the same number of threads. Many frameworks will read the environment variable `OMP_NUM_THREADS`, which can be set when running your script:\r\n\r\n```bash\r\nOMP_NUM_THREADS=4 python3 my_script.py\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Faster Whisper transcription with CTranslate2",
    "version": "1.0.4.post4",
    "project_urls": {
        "Homepage": "https://github.com/SYSTRAN/faster-whisper"
    },
    "split_keywords": [
        "openai",
        "whisper",
        "speech",
        "ctranslate2",
        "inference",
        "quantization",
        "transformer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e5338d1116bc98d0987722892814d50a411bdccfb14dece6da4cddc654e46fe1",
                "md5": "2605b48b7799a32d4c4e5d5327bafdfa",
                "sha256": "ae4b5d9ab4b3890e580d1fa457508f70103ceb3c800b789cf0e39ac9b0500d9e"
            },
            "downloads": -1,
            "filename": "topai_faster_whisper-1.0.4.post4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2605b48b7799a32d4c4e5d5327bafdfa",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18420931,
            "upload_time": "2024-10-17T09:28:00",
            "upload_time_iso_8601": "2024-10-17T09:28:00.070581Z",
            "url": "https://files.pythonhosted.org/packages/e5/33/8d1116bc98d0987722892814d50a411bdccfb14dece6da4cddc654e46fe1/topai_faster_whisper-1.0.4.post4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4cac78e4ac0a6010b1009d0c5cc1a6e786995406d770260a22be77fad2927b0e",
                "md5": "c11551759192a18376facf6c8302bd88",
                "sha256": "3a6f6889a0fca5d5abd989eb31f2764820e2e943414caae8081bbf53fa2ffd8e"
            },
            "downloads": -1,
            "filename": "topai_faster_whisper-1.0.4.post4.tar.gz",
            "has_sig": false,
            "md5_digest": "c11551759192a18376facf6c8302bd88",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 18424653,
            "upload_time": "2024-10-17T09:28:10",
            "upload_time_iso_8601": "2024-10-17T09:28:10.791051Z",
            "url": "https://files.pythonhosted.org/packages/4c/ac/78e4ac0a6010b1009d0c5cc1a6e786995406d770260a22be77fad2927b0e/topai_faster_whisper-1.0.4.post4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-17 09:28:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SYSTRAN",
    "github_project": "faster-whisper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "ctranslate2",
            "specs": [
                [
                    "<",
                    "5"
                ],
                [
                    ">=",
                    "4.0"
                ]
            ]
        },
        {
            "name": "huggingface_hub",
            "specs": [
                [
                    ">=",
                    "0.13"
                ]
            ]
        },
        {
            "name": "tokenizers",
            "specs": [
                [
                    "<",
                    "1"
                ],
                [
                    ">=",
                    "0.13"
                ]
            ]
        },
        {
            "name": "onnxruntime",
            "specs": [
                [
                    "<",
                    "2"
                ],
                [
                    ">=",
                    "1.14"
                ]
            ]
        },
        {
            "name": "pyannote-audio",
            "specs": [
                [
                    ">=",
                    "3.1.1"
                ]
            ]
        },
        {
            "name": "torch",
            "specs": [
                [
                    ">=",
                    "2.1.1"
                ]
            ]
        },
        {
            "name": "torchaudio",
            "specs": [
                [
                    ">=",
                    "2.1.2"
                ]
            ]
        },
        {
            "name": "tqdm",
            "specs": []
        }
    ],
    "lcname": "topai-faster-whisper"
}
        
Elapsed time: 0.40099s