diff --git a/README.md b/README.md index f68995f..97bd9d8 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,14 @@ whisperlivekit-server --model tiny.en # Open your browser at http://localhost:8000 ``` +### Quick Start with SSL +```bash +# You must provide a certificate and key +whisperlivekit-server -ssl-certfile public.crt --ssl-keyfile private.key + +# Open your browser at https://localhost:8000 +``` + That's it! Start speaking and watch your words appear on screen. ## 🛠️ Installation Options @@ -201,6 +209,8 @@ WhisperLiveKit offers extensive configuration options: | `--no-vad` | Disable Voice Activity Detection | `False` | | `--buffer_trimming` | Buffer trimming strategy (`sentence` or `segment`) | `segment` | | `--warmup-file` | Audio file path for model warmup | `jfk.wav` | +| `--ssl-certfile` | Path to the SSL certificate file (for HTTPS support) | `None` | +| `--ssl-keyfile` | Path to the SSL private key file (for HTTPS support) | `None` | ## 🔧 How It Works diff --git a/whisperlivekit/basic_server.py b/whisperlivekit/basic_server.py index 0510580..87e2409 100644 --- a/whisperlivekit/basic_server.py +++ b/whisperlivekit/basic_server.py @@ -8,7 +8,8 @@ from whisperlivekit.audio_processor import AudioProcessor import asyncio import logging -import os +import os, sys +import argparse logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") logging.getLogger().setLevel(logging.WARNING) @@ -74,14 +75,29 @@ def main(): args = parse_args() - uvicorn.run( - "whisperlivekit.basic_server:app", - host=args.host, - port=args.port, - reload=False, - log_level="info", - lifespan="on", - ) + uvicorn_kwargs = { + "app": "whisperlivekit.basic_server:app", + "host":args.host, + "port":args.port, + "reload": False, + "log_level": "info", + "lifespan": "on", + } + + ssl_kwargs = {} + if args.ssl_certfile or args.ssl_keyfile: + if not (args.ssl_certfile and args.ssl_keyfile): + raise ValueError("Both --ssl-certfile and --ssl-keyfile must be specified together.") + ssl_kwargs = { + "ssl_certfile": args.ssl_certfile, + "ssl_keyfile": args.ssl_keyfile + } + + + if ssl_kwargs: + uvicorn_kwargs = {**uvicorn_kwargs, **ssl_kwargs} + + uvicorn.run(**uvicorn_kwargs) if __name__ == "__main__": main() diff --git a/whisperlivekit/web/live_transcription.html b/whisperlivekit/web/live_transcription.html index 50f981a..d75dddd 100644 --- a/whisperlivekit/web/live_transcription.html +++ b/whisperlivekit/web/live_transcription.html @@ -321,7 +321,8 @@ const host = window.location.hostname || "localhost"; const port = window.location.port || "8000"; - const defaultWebSocketUrl = `ws://${host}:${port}/asr`; + const protocol = window.location.protocol === "https:" ? "wss" : "ws"; + const defaultWebSocketUrl = `${protocol}://${host}:${port}/asr`; websocketInput.value = defaultWebSocketUrl; websocketUrl = defaultWebSocketUrl;