### Install FFmpeg for Whisper STT (Bash) Source: https://github.com/progressing-llama/whisper-live-stt/blob/master/README.md Installs the FFmpeg multimedia framework, a crucial dependency for the Whisper model to process audio effectively. Instructions are provided for various operating systems including Ubuntu/Debian, Arch Linux, macOS, and Windows. ```bash # on Ubuntu or Debian sudo apt update && sudo apt install ffmpeg # on Arch Linux sudo pacman -S ffmpeg # on MacOS using Homebrew (https://brew.sh/) brew install ffmpeg # on Windows using Chocolatey (https://chocolatey.org/) choco install ffmpeg # on Windows using Scoop (https://scoop.sh/) scoop install ffmpeg ``` -------------------------------- ### Install Whisper Live STT Dependencies (Bash) Source: https://github.com/progressing-llama/whisper-live-stt/blob/master/README.md Installs the core Python libraries required for live speech-to-text transcription using Whisper. This includes the openai-whisper package itself, along with pyaudio for audio input, librosa for audio processing, and numpy for numerical operations. ```bash pip install -U openai-whisper pip install pyaudio pip install librosa pip install numpy ``` -------------------------------- ### Start and Monitor Live Transcription Source: https://context7.com/progressing-llama/whisper-live-stt/llms.txt Starts the real-time transcription engine, which utilizes daemon threads for audio capture, processing, and transcript building. The transcribed text can be polled periodically. ```python import os import time from live_stt_2 import LiveSTT print("Initializing...") stt = LiveSTT() print("Running") def clear_screen(): if os.name == 'nt': _ = os.system('cls') else: _ = os.system('clear') # Start the transcription engine stt.start() # Poll for transcribed text while True: time.sleep(2) clear_screen() print("Predicted Text:") print(stt.confirmed_text) # Access current prediction print("\nCurrent Segment:") print(stt.current_predicted_text) ``` -------------------------------- ### Run Live Speech-to-Text Transcription (Python) Source: https://github.com/progressing-llama/whisper-live-stt/blob/master/README.md Demonstrates how to initialize and run the live speech-to-text transcription service using the `LiveSTT` class. It includes functions to clear the console screen and continuously prints the confirmed transcribed text as it becomes available. ```python import os import time from live_stt_2 import LiveSTT print("Initializing...") stt = LiveSTT() #stt.calculate_recommended_settings(5) print("Running") def clear_screen(): # For Windows if os.name == 'nt': _ = os.system('cls') # For macOS and Linux else: _ = os.system('clear') stt.start() while True: time.sleep(2) clear_screen() print("Predicted Text:") print(stt.confirmed_text) ``` -------------------------------- ### Initialize LiveSTT Transcription Engine Source: https://context7.com/progressing-llama/whisper-live-stt/llms.txt Initializes the main class for real-time speech transcription. Allows configuration of processing and capture window durations, as well as the Whisper model. The model is automatically loaded to a CUDA GPU if available. ```python from live_stt_2 import LiveSTT # Initialize with default settings (4s processing, 8s capture window, turbo model) stt = LiveSTT() # Or customize parameters stt = LiveSTT( processing_time=4, # Time between processing steps in seconds capture_time=8, # Audio capture window size in seconds whisper_model="turbo" # Options: "tiny", "base", "small", "medium", "large", "turbo" ) # The model is automatically loaded to CUDA GPU # Window size and step size are calculated based on audio frequency (44.1kHz) and chunk size (2048) ``` -------------------------------- ### Record Audio Chunks with PyAudio Source: https://context7.com/progressing-llama/whisper-live-stt/llms.txt Captures raw audio data in chunks using PyAudio. Configurable sample rate and buffer size allow control over audio input parameters. Ensure the recorder is always closed after use. ```python from AudioInput import AudioRecorder # Initialize audio recorder recorder = AudioRecorder( frequency=44100, # Sample rate in Hz chunk=1024 # Buffer size per read ) # Capture audio chunks try: while True: # Returns raw audio data as bytes (16-bit PCM) audio_chunk = recorder.record() # Process audio_chunk... except KeyboardInterrupt: pass finally: # Always close the recorder recorder.close() ``` -------------------------------- ### Manually Transcribe Audio Window with Whisper (Python) Source: https://context7.com/progressing-llama/whisper-live-stt/llms.txt This snippet shows how to directly transcribe a specific audio window using the Whisper model with the LiveSTT class. It takes raw audio frames and a TimeFrame object as input, returning the transcribed text. The result is also added to an internal queue with metadata. ```python from live_stt_2 import LiveSTT, TimeFrame import numpy as np stt = LiveSTT(whisper_model="turbo") stt.start() # process_data: list of raw audio byte frames # Each frame is bytes object from AudioRecorder process_data = [...] # Your audio frames time_frame = TimeFrame(start=0.0, end=8.0) # Transcribe the audio window # Returns transcribed text and adds result to queue transcribed_text = stt.transcribe(process_data, time_frame) print(f"Transcription: {transcribed_text}") # The result is also added to internal queue with metadata: # { # "text": transcribed_text, # "weight": confidence_score, # "time_frame": time_frame # } ``` -------------------------------- ### Manage TimeFrame Boundaries Source: https://context7.com/progressing-llama/whisper-live-stt/llms.txt A utility class for defining and managing temporal boundaries of audio segments. It provides methods to check for time intersections between segments and access segment duration. ```python from live_stt_2 import TimeFrame # Create time frames representing audio segments frame1 = TimeFrame(start=0.0, end=5.0) # 0-5 seconds frame2 = TimeFrame(start=4.0, end=9.0) # 4-9 seconds frame3 = TimeFrame(start=10.0, end=15.0) # 10-15 seconds # Check if frames intersect (overlap in time) if frame1.intersects(frame2): print(f"Frames overlap") # True - they overlap from 4-5 seconds if frame1.intersects(frame3): print(f"Frames overlap") # False - no overlap # Access properties print(f"Duration: {frame1.duration} seconds") # 5.0 ``` -------------------------------- ### Detect Speech in Audio Frames with WebRTC VAD (Python) Source: https://context7.com/progressing-llama/whisper-live-stt/llms.txt This snippet demonstrates how to use the LiveSTT class to detect speech in raw audio frames using WebRTC VAD. It filters out silence to optimize transcription processing. The function `detect_speech_in_frames` returns a boolean indicating whether speech was detected. ```python from live_stt_2 import LiveSTT import numpy as np stt = LiveSTT() # audio_frames is a list of raw audio byte data at 44.1kHz audio_frames = [...] # Your captured audio frames # Returns True if speech detected (>30% of frames contain speech) has_speech = stt.detect_speech_in_frames(audio_frames) if has_speech: # Process the audio for transcription print("Speech detected, transcribing...") else: # Skip transcription to save compute print("Silence detected, skipping...") ``` -------------------------------- ### Intelligently Concatenate Text Segments Source: https://context7.com/progressing-llama/whisper-live-stt/llms.txt Provides a function for merging two text strings intelligently, considering punctuation and capitalization rules to ensure natural sentence flow. Handles cases like leading punctuation, trailing periods, and sentence capitalization. ```python from whisper_correction import intelligent_concatenate # Rule 1: String2 starts with punctuation text1 = "Hello world." text2 = ", how are you" result = intelligent_concatenate(text1, text2) print(result) # "Hello world, how are you" # Rule 2: String2 starts lowercase, string1 ends with period text1 = "Hello world." text2 = "and welcome" result = intelligent_concatenate(text1, text2) print(result) # "Hello world and welcome" # Rule 3: String2 starts uppercase, string1 has no punctuation text1 = "Hello world" text2 = "Welcome home" result = intelligent_concatenate(text1, text2) print(result) # "Hello world. Welcome home" # Default: Simple space concatenation text1 = "hello" text2 = "world" result = intelligent_concatenate(text1, text2) print(result) # "hello world" ``` -------------------------------- ### Stop Live Transcription Engine Source: https://context7.com/progressing-llama/whisper-live-stt/llms.txt Gracefully stops the real-time transcription engine and cleans up associated resources. The `stop()` method can be called explicitly, or resource cleanup can be left to the `__del__` method. ```python from live_stt_2 import LiveSTT stt = LiveSTT() stt.start() # ... do transcription work ... # Stop transcription stt.stop() # The __del__ method automatically handles cleanup # but you can manually call stop() when needed ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.