Expose ClientManager arguments to be passed from client
Signed-off-by: makaveli10 <vineet.suryan@collabora.com>
This commit is contained in:
+16
-3
@@ -30,7 +30,9 @@ class Client:
|
|||||||
model="small",
|
model="small",
|
||||||
srt_file_path="output.srt",
|
srt_file_path="output.srt",
|
||||||
use_vad=True,
|
use_vad=True,
|
||||||
log_transcription=True
|
log_transcription=True,
|
||||||
|
max_clients=4,
|
||||||
|
max_connection_time=600,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Initializes a Client instance for audio recording and streaming to a server.
|
Initializes a Client instance for audio recording and streaming to a server.
|
||||||
@@ -59,6 +61,8 @@ class Client:
|
|||||||
self.last_segment = None
|
self.last_segment = None
|
||||||
self.last_received_segment = None
|
self.last_received_segment = None
|
||||||
self.log_transcription = log_transcription
|
self.log_transcription = log_transcription
|
||||||
|
self.max_clients = max_clients
|
||||||
|
self.max_connection_time = max_connection_time
|
||||||
|
|
||||||
if translate:
|
if translate:
|
||||||
self.task = "translate"
|
self.task = "translate"
|
||||||
@@ -199,7 +203,9 @@ class Client:
|
|||||||
"language": self.language,
|
"language": self.language,
|
||||||
"task": self.task,
|
"task": self.task,
|
||||||
"model": self.model,
|
"model": self.model,
|
||||||
"use_vad": self.use_vad
|
"use_vad": self.use_vad,
|
||||||
|
"max_clients": self.max_clients,
|
||||||
|
"max_connection_time": self.max_connection_time,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -681,8 +687,15 @@ class TranscriptionClient(TranscriptionTeeClient):
|
|||||||
output_recording_filename="./output_recording.wav",
|
output_recording_filename="./output_recording.wav",
|
||||||
output_transcription_path="./output.srt",
|
output_transcription_path="./output.srt",
|
||||||
log_transcription=True,
|
log_transcription=True,
|
||||||
|
max_clients=4,
|
||||||
|
max_connection_time=600,
|
||||||
):
|
):
|
||||||
self.client = Client(host, port, lang, translate, model, srt_file_path=output_transcription_path, use_vad=use_vad, log_transcription=log_transcription)
|
self.client = Client(
|
||||||
|
host, port, lang, translate, model, srt_file_path=output_transcription_path,
|
||||||
|
use_vad=use_vad, log_transcription=log_transcription, max_clients=max_clients,
|
||||||
|
max_connection_time=max_connection_time
|
||||||
|
)
|
||||||
|
|
||||||
if save_output_recording and not output_recording_filename.endswith(".wav"):
|
if save_output_recording and not output_recording_filename.endswith(".wav"):
|
||||||
raise ValueError(f"Please provide a valid `output_recording_filename`: {output_recording_filename}")
|
raise ValueError(f"Please provide a valid `output_recording_filename`: {output_recording_filename}")
|
||||||
if not output_transcription_path.endswith(".srt"):
|
if not output_transcription_path.endswith(".srt"):
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ class TranscriptionServer:
|
|||||||
RATE = 16000
|
RATE = 16000
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.client_manager = ClientManager()
|
self.client_manager = None
|
||||||
self.no_voice_activity_chunks = 0
|
self.no_voice_activity_chunks = 0
|
||||||
self.use_vad = True
|
self.use_vad = True
|
||||||
self.single_model = False
|
self.single_model = False
|
||||||
@@ -224,6 +224,12 @@ class TranscriptionServer:
|
|||||||
logging.info("New client connected")
|
logging.info("New client connected")
|
||||||
options = websocket.recv()
|
options = websocket.recv()
|
||||||
options = json.loads(options)
|
options = json.loads(options)
|
||||||
|
|
||||||
|
if self.client_manager is None:
|
||||||
|
max_clients = options.get('max_clients', 4)
|
||||||
|
max_connection_time = options.get('max_connection_time', 600)
|
||||||
|
self.client_manager = ClientManager(max_clients, max_connection_time)
|
||||||
|
|
||||||
self.use_vad = options.get('use_vad')
|
self.use_vad = options.get('use_vad')
|
||||||
if self.client_manager.is_server_full(websocket, options):
|
if self.client_manager.is_server_full(websocket, options):
|
||||||
websocket.close()
|
websocket.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user