allow passing of cert and key locations to uvicorn via package
Browse files- whisperlivekit/basic_server.py +32 -10
whisperlivekit/basic_server.py
CHANGED
|
@@ -8,7 +8,8 @@ from whisperlivekit.audio_processor import AudioProcessor
|
|
| 8 |
|
| 9 |
import asyncio
|
| 10 |
import logging
|
| 11 |
-
import os
|
|
|
|
| 12 |
|
| 13 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 14 |
logging.getLogger().setLevel(logging.WARNING)
|
|
@@ -71,16 +72,37 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
| 71 |
def main():
|
| 72 |
"""Entry point for the CLI command."""
|
| 73 |
import uvicorn
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
temp_kit = WhisperLiveKit(transcription=False, diarization=False)
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
"whisperlivekit.basic_server:app",
|
| 79 |
-
host
|
| 80 |
-
port
|
| 81 |
-
reload
|
| 82 |
-
log_level
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
if __name__ == "__main__":
|
| 86 |
main()
|
|
|
|
| 8 |
|
| 9 |
import asyncio
|
| 10 |
import logging
|
| 11 |
+
import os, sys
|
| 12 |
+
import argparse
|
| 13 |
|
| 14 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 15 |
logging.getLogger().setLevel(logging.WARNING)
|
|
|
|
| 72 |
def main():
|
| 73 |
"""Entry point for the CLI command."""
|
| 74 |
import uvicorn
|
| 75 |
+
|
| 76 |
+
parser = argparse.ArgumentParser(description="Run the WhisperLiveKit server.")
|
| 77 |
+
parser.add_argument("--ssl-certfile", type=str, help="Path to the SSL certificate file.")
|
| 78 |
+
parser.add_argument("--ssl-keyfile", type=str, help="Path to the SSL private key file.")
|
| 79 |
+
args, unknown = parser.parse_known_args()
|
| 80 |
+
|
| 81 |
+
ssl_kwargs = {}
|
| 82 |
+
if args.ssl_certfile or args.ssl_keyfile:
|
| 83 |
+
if not (args.ssl_certfile and args.ssl_keyfile):
|
| 84 |
+
raise ValueError("Both --ssl-certfile and --ssl-keyfile must be specified together.")
|
| 85 |
+
ssl_kwargs = {
|
| 86 |
+
"ssl_certfile": args.ssl_certfile,
|
| 87 |
+
"ssl_keyfile": args.ssl_keyfile
|
| 88 |
+
}
|
| 89 |
+
# Remove uvicorn-specific args from the context to avoid tripping up other parts of the stack
|
| 90 |
+
sys.argv = [sys.argv[0]] + unknown
|
| 91 |
+
|
| 92 |
temp_kit = WhisperLiveKit(transcription=False, diarization=False)
|
| 93 |
+
|
| 94 |
+
uvicorn_kwargs = {
|
| 95 |
+
"app": "whisperlivekit.basic_server:app",
|
| 96 |
+
"host":temp_kit.args.host,
|
| 97 |
+
"port":temp_kit.args.port,
|
| 98 |
+
"reload": True,
|
| 99 |
+
"log_level": "info",
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
if ssl_kwargs:
|
| 103 |
+
uvicorn_kwargs = {**uvicorn_kwargs, **ssl_kwargs}
|
| 104 |
+
|
| 105 |
+
uvicorn.run(**uvicorn_kwargs)
|
| 106 |
|
| 107 |
if __name__ == "__main__":
|
| 108 |
main()
|