From 02de5993e68231cc8171db0f7bd986ae4429403d Mon Sep 17 00:00:00 2001 From: Chris Margach Date: Thu, 10 Apr 2025 13:42:30 +0900 Subject: [PATCH 1/4] allow passing of cert and key locations to uvicorn via package --- whisperlivekit/basic_server.py | 42 ++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/whisperlivekit/basic_server.py b/whisperlivekit/basic_server.py index ef979d7..110219a 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) @@ -71,16 +72,37 @@ async def websocket_endpoint(websocket: WebSocket): def main(): """Entry point for the CLI command.""" import uvicorn - + + parser = argparse.ArgumentParser(description="Run the WhisperLiveKit server.") + parser.add_argument("--ssl-certfile", type=str, help="Path to the SSL certificate file.") + parser.add_argument("--ssl-keyfile", type=str, help="Path to the SSL private key file.") + args, unknown = parser.parse_known_args() + + 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 + } + # Remove uvicorn-specific args from the context to avoid tripping up other parts of the stack + sys.argv = [sys.argv[0]] + unknown + temp_kit = WhisperLiveKit(transcription=False, diarization=False) - - uvicorn.run( - "whisperlivekit.basic_server:app", - host=temp_kit.args.host, - port=temp_kit.args.port, - reload=True, - log_level="info" - ) + + uvicorn_kwargs = { + "app": "whisperlivekit.basic_server:app", + "host":temp_kit.args.host, + "port":temp_kit.args.port, + "reload": True, + "log_level": "info", + } + + if ssl_kwargs: + uvicorn_kwargs = {**uvicorn_kwargs, **ssl_kwargs} + + uvicorn.run(**uvicorn_kwargs) if __name__ == "__main__": main() From d53b7a323a6b7edce44c324c323abd4995e3152a Mon Sep 17 00:00:00 2001 From: Chris Margach Date: Thu, 10 Apr 2025 13:46:52 +0900 Subject: [PATCH 2/4] update sample html to use wss in case of https --- whisperlivekit/web/live_transcription.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whisperlivekit/web/live_transcription.html b/whisperlivekit/web/live_transcription.html index 50f981a..6c81c72 100644 --- a/whisperlivekit/web/live_transcription.html +++ b/whisperlivekit/web/live_transcription.html @@ -321,7 +321,7 @@ const host = window.location.hostname || "localhost"; const port = window.location.port || "8000"; - const defaultWebSocketUrl = `ws://${host}:${port}/asr`; + const defaultWebSocketUrl = `${window.location.protocol === "https:" ? "wss" : "ws"}://${host}:${port}/asr`; websocketInput.value = defaultWebSocketUrl; websocketUrl = defaultWebSocketUrl; From 3c58bfcfa203695f2b504026a4d3f3e1dfe481a6 Mon Sep 17 00:00:00 2001 From: Chris Margach Date: Thu, 10 Apr 2025 13:47:09 +0900 Subject: [PATCH 3/4] update readme for package launch with SSL --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index f68995f..4ffbacc 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 From b708890788cfa8f3911f3ca641ff1e50ba033679 Mon Sep 17 00:00:00 2001 From: Quentin Fuxa Date: Fri, 11 Apr 2025 12:14:14 +0200 Subject: [PATCH 4/4] protocol default to ws --- README.md | 2 ++ whisperlivekit/web/live_transcription.html | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ffbacc..97bd9d8 100644 --- a/README.md +++ b/README.md @@ -209,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/web/live_transcription.html b/whisperlivekit/web/live_transcription.html index 6c81c72..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 = `${window.location.protocol === "https:" ? "wss" : "ws"}://${host}:${port}/asr`; + const protocol = window.location.protocol === "https:" ? "wss" : "ws"; + const defaultWebSocketUrl = `${protocol}://${host}:${port}/asr`; websocketInput.value = defaultWebSocketUrl; websocketUrl = defaultWebSocketUrl;