allow passing of cert and key locations to uvicorn via package
This commit is contained in:
parent
d94560ef37
commit
02de5993e6
1 changed files with 32 additions and 10 deletions
|
|
@ -8,7 +8,8 @@ from whisperlivekit.audio_processor import AudioProcessor
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os, sys
|
||||||
|
import argparse
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
||||||
logging.getLogger().setLevel(logging.WARNING)
|
logging.getLogger().setLevel(logging.WARNING)
|
||||||
|
|
@ -71,16 +72,37 @@ async def websocket_endpoint(websocket: WebSocket):
|
||||||
def main():
|
def main():
|
||||||
"""Entry point for the CLI command."""
|
"""Entry point for the CLI command."""
|
||||||
import uvicorn
|
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)
|
temp_kit = WhisperLiveKit(transcription=False, diarization=False)
|
||||||
|
|
||||||
uvicorn.run(
|
uvicorn_kwargs = {
|
||||||
"whisperlivekit.basic_server:app",
|
"app": "whisperlivekit.basic_server:app",
|
||||||
host=temp_kit.args.host,
|
"host":temp_kit.args.host,
|
||||||
port=temp_kit.args.port,
|
"port":temp_kit.args.port,
|
||||||
reload=True,
|
"reload": True,
|
||||||
log_level="info"
|
"log_level": "info",
|
||||||
)
|
}
|
||||||
|
|
||||||
|
if ssl_kwargs:
|
||||||
|
uvicorn_kwargs = {**uvicorn_kwargs, **ssl_kwargs}
|
||||||
|
|
||||||
|
uvicorn.run(**uvicorn_kwargs)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue