Update README.md
This commit is contained in:
parent
81268a7ca3
commit
38cb54640f
1 changed files with 39 additions and 32 deletions
29
README.md
29
README.md
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue