Skip to main content

speechlib is a library that unifies speaker diarization, transcription and speaker recognition in a single pipeline to create transcripts for audio conversations with actual speaker names and time tags. This library also contain audio preprocessor functions.

Project description

Recall.ai - Meeting Transcription API

If you’re looking for a transcription API for meetings, consider checking out Recall.ai, an API that works with Zoom, Google Meet, Microsoft Teams, and more. Recall.ai diarizes by pulling the speaker data and separate audio streams from the meeting platforms, which means 100% accurate speaker diarization with actual speaker names.

Speechlib

Run your IDE as administrator

you will get following error if administrator permission is not there:

OSError: [WinError 1314] A required privilege is not held by the client

Requirements

  • Python 3.8 or greater

GPU execution

GPU execution needs CUDA 11.

GPU execution requires the following NVIDIA libraries to be installed:

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

Google Colab:

on google colab run this to install CUDA dependencies:

!apt install libcublas11

You can see this example notebook

installation:

pip install speechlib
or
uv add speechlib

Dependencies:

dependencies = [
    "accelerate>=1.12.0",
    "assemblyai>=0.50.0",
    "faster-whisper>=1.2.1",
    "huggingface-hub==0.36.0",
    "numpy==1.26.4",
    "openai-whisper>=20250625",
    "pyannote-audio==3.4.0",
    "pydub>=0.25.1",
    "speechbrain==1.0.3",
    "torch==2.2.0",
    "torchaudio==2.2.0",
    "torchvision==0.17.0",
    "transformers>=4.57.6",
]

Introduction

This library does speaker diarization, speaker recognition, and transcription on a single wav file to provide a transcript with actual speaker names. This library will also return an array containing result information. ⚙

This library contains following audio preprocessing functions:

  1. convert other audio formats to wav

  2. convert stereo wav file to mono

  3. re-encode the wav file to have 16-bit PCM encoding

Transcriptor method takes 7 arguments.

  1. file to transcribe

  2. log_folder to store transcription

  3. language used for transcribing (language code is used)

  4. model size ("tiny", "small", "medium", "large", "large-v1", "large-v2", "large-v3")

  5. ACCESS_TOKEN: huggingface acccess token (also get permission to access pyannote/speaker-diarization@2.1)

  6. voices_folder (contains speaker voice samples for speaker recognition)

  7. quantization: this determine whether to use int8 quantization or not. Quantization may speed up the process but lower the accuracy.

voices_folder should contain subfolders named with speaker names. Each subfolder belongs to a speaker and it can contain many voice samples. This will be used for speaker recognition to identify the speaker.

if voices_folder is not provided then speaker tags will be arbitrary.

log_folder is to store the final transcript as a text file.

transcript will also indicate the timeframe in seconds where each speaker speaks.

Transcription example:

import os
from speechlib import Transcriptor

file = "obama_zach.wav"  # your audio file
voices_folder = "" # voices folder containing voice samples for recognition
language = "en"          # language code
log_folder = "logs"      # log folder for storing transcripts
modelSize = "tiny"     # size of model to be used [tiny, small, medium, large-v1, large-v2, large-v3]
quantization = False   # setting this 'True' may speed up the process but lower the accuracy
ACCESS_TOKEN = "huggingface api key" # get permission to access pyannote/speaker-diarization@2.1 on huggingface

# quantization only works on faster-whisper
transcriptor = Transcriptor(file, log_folder, language, modelSize, ACCESS_TOKEN, voices_folder, quantization)

# use normal whisper
res = transcriptor.whisper()

# use faster-whisper (simply faster)
res = transcriptor.faster_whisper()

# use a custom trained whisper model
res = transcriptor.custom_whisper("D:/whisper_tiny_model/tiny.pt")

# use a huggingface whisper model
res = transcriptor.huggingface_model("Jingmiao/whisper-small-chinese_base")

# use assembly ai model
res = transcriptor.assemby_ai_model("assemblyAI api key")

res --> [["start", "end", "text", "speaker"], ["start", "end", "text", "speaker"]...]

if you don't want speaker names: keep voices_folder as an empty string ""

start: starting time of speech in seconds
end: ending time of speech in seconds
text: transcribed text for speech during start and end
speaker: speaker of the text

voices folder structure:

voices_folder
|---> person1
|        |---> sample1.wav
|        |---> sample2.wav
|                ...
|
|---> person2
|        |---> sample1.wav
|        |---> sample2.wav
|                ...
|--> ...

supported language codes:

"af", "am", "ar", "as", "az", "ba", "be", "bg", "bn", "bo", "br", "bs", "ca", "cs", "cy", "da", "de", "el", "en", "es", "et", "eu", "fa", "fi", "fo", "fr", "gl", "gu", "ha", "haw", "he", "hi", "hr", "ht", "hu", "hy", "id", "is","it", "ja", "jw", "ka", "kk", "km", "kn", "ko", "la", "lb", "ln", "lo", "lt", "lv", "mg", "mi", "mk", "ml", "mn","mr", "ms", "mt", "my", "ne", "nl", "nn", "no", "oc", "pa", "pl", "ps", "pt", "ro", "ru", "sa", "sd", "si", "sk","sl", "sn", "so", "sq", "sr", "su", "sv", "sw", "ta", "te", "tg", "th", "tk", "tl", "tr", "tt", "uk", "ur", "uz","vi", "yi", "yo", "zh", "yue"

supported language names:

"Afrikaans", "Amharic", "Arabic", "Assamese", "Azerbaijani", "Bashkir", "Belarusian", "Bulgarian", "Bengali","Tibetan", "Breton", "Bosnian", "Catalan", "Czech", "Welsh", "Danish", "German", "Greek", "English", "Spanish","Estonian", "Basque", "Persian", "Finnish", "Faroese", "French", "Galician", "Gujarati", "Hausa", "Hawaiian","Hebrew", "Hindi", "Croatian", "Haitian", "Hungarian", "Armenian", "Indonesian", "Icelandic", "Italian", "Japanese","Javanese", "Georgian", "Kazakh", "Khmer", "Kannada", "Korean", "Latin", "Luxembourgish", "Lingala", "Lao","Lithuanian", "Latvian", "Malagasy", "Maori", "Macedonian", "Malayalam", "Mongolian", "Marathi", "Malay", "Maltese","Burmese", "Nepali", "Dutch", "Norwegian Nynorsk", "Norwegian", "Occitan", "Punjabi", "Polish", "Pashto","Portuguese", "Romanian", "Russian", "Sanskrit", "Sindhi", "Sinhalese", "Slovak", "Slovenian", "Shona", "Somali","Albanian", "Serbian", "Sundanese", "Swedish", "Swahili", "Tamil", "Telugu", "Tajik", "Thai", "Turkmen", "Tagalog","Turkish", "Tatar", "Ukrainian", "Urdu", "Uzbek", "Vietnamese", "Yiddish", "Yoruba", "Chinese", "Cantonese",

Audio preprocessing example:

from speechlib import PreProcessor

file = "obama1.mp3"
#initialize
prep = PreProcessor()
# convert mp3 to wav
wav_file = prep.convert_to_wav(file)

# convert wav file from stereo to mono
prep.convert_to_mono(wav_file)

# re-encode wav file to have 16-bit PCM encoding
prep.re_encode(wav_file)

Performance

These metrics are from Google Colab tests.
These metrics do not take into account model download times.
These metrics are done without quantization enabled.
(quantization will make this even faster)

metrics for faster-whisper "tiny" model:
    on gpu:
        audio name: obama_zach.wav
        duration: 6 min 36 s
        diarization time: 24s
        speaker recognition time: 10s
        transcription time: 64s


metrics for faster-whisper "small" model:
    on gpu:
        audio name: obama_zach.wav
        duration: 6 min 36 s
        diarization time: 24s
        speaker recognition time: 10s
        transcription time: 95s


metrics for faster-whisper "medium" model:
    on gpu:
        audio name: obama_zach.wav
        duration: 6 min 36 s
        diarization time: 24s
        speaker recognition time: 10s
        transcription time: 193s


metrics for faster-whisper "large" model:
    on gpu:
        audio name: obama_zach.wav
        duration: 6 min 36 s
        diarization time: 24s
        speaker recognition time: 10s
        transcription time: 343s

Citation

If you use Speechlib in your research or project, please cite it as:

@software{speechlib,
  author       = {NavodPeiris},
  title        = {Speechlib: Speaker Diarization, Recognition, and Transcription in a Single Pipeline},
  year         = {2024},
  publisher    = {GitHub},
  url          = {https://github.com/NavodPeiris/speechlib}
}

Sponsorship

If you find Speechlib useful, please consider supporting its development:

Your support helps maintain and improve the library. Thank you!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

speechlib-1.1.17.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

speechlib-1.1.17-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file speechlib-1.1.17.tar.gz.

File metadata

  • Download URL: speechlib-1.1.17.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for speechlib-1.1.17.tar.gz
Algorithm Hash digest
SHA256 4bea6c03f5d94dd9cd3143403486cd2c45ee5d19825dfead9af1f457cd496ba3
MD5 420fdce8f4767e137f7aca7cf0ed2469
BLAKE2b-256 6789766d42c936240858e395cd6c469e02a87d9bebcf17b8863ffa4e794b4937

See more details on using hashes here.

File details

Details for the file speechlib-1.1.17-py3-none-any.whl.

File metadata

  • Download URL: speechlib-1.1.17-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for speechlib-1.1.17-py3-none-any.whl
Algorithm Hash digest
SHA256 0e352fc98b02939d5a8c5fd50657192253ef37db307bee02f3d978cf7666678c
MD5 8dc3a16ef846529615013a8837a0d1df
BLAKE2b-256 de6ed5fa144b0f753efce68fd1b7bd67aa38442e683affd6ebc0ff9f74c761b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page