Update README.md

This commit is contained in:
Quentin Fuxa 2025-03-19 15:49:39 +01:00 committed by GitHub
parent 81268a7ca3
commit 38cb54640f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -89,23 +89,30 @@ Then open your browser at `http://localhost:8000` (or your specified host and po
```python
from whisperlivekit import WhisperLiveKit
from whisperlivekit.audio_processor import AudioProcessor
from fastapi import FastAPI, WebSocket
# Initialize WhisperLiveKit with custom parameters
kit = WhisperLiveKit(
model="tiny.en",
diarization=True,
)
# Create a FastAPI application
app = FastAPI()
kit = WhisperLiveKit(model="medium", diarization=True)
app = FastAPI() # Create a FastAPI application
@app.get("/")
async def get():
# Use the built-in web interface
return HTMLResponse(kit.web_interface())
return HTMLResponse(kit.web_interface()) # Use the built-in web interface
# Your websocket endpoints for audio processing...
async def handle_websocket_results(websocket, results_generator): # Sends results to frontend
async for response in results_generator:
await websocket.send_json(response)
@app.websocket("/asr")
async def websocket_endpoint(websocket: WebSocket):
audio_processor = AudioProcessor()
await websocket.accept()
results_generator = await audio_processor.create_tasks()
websocket_task = asyncio.create_task(handle_websocket_results(websocket, results_generator))
while True:
message = await websocket.receive_bytes()
await audio_processor.process_audio(message)
```
For a complete audio processing example, check [whisper_fastapi_online_server.py](https://github.com/QuentinFuxa/WhisperLiveKit/blob/main/whisper_fastapi_online_server.py)