Skip to content

Commit 858e527

Browse files
authored
Add support in WSS
1 parent 18de63c commit 858e527

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

whisper_live/client.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ def __init__(
7070
self.audio_bytes = None
7171

7272
if host is not None and port is not None:
73-
socket_url = f"ws://{host}:{port}"
73+
if port == 443:
74+
socket_url = f"wss://{host}"
75+
else:
76+
socket_url = f"ws://{host}:{port}"
7477
self.client_socket = websocket.WebSocketApp(
7578
socket_url,
7679
on_open=lambda ws: self.on_open(ws),
@@ -79,6 +82,7 @@ def __init__(
7982
on_close=lambda ws, close_status_code, close_msg: self.on_close(
8083
ws, close_status_code, close_msg
8184
),
85+
header=['User-Agent: WhisperLiveClient']
8286
)
8387
else:
8488
print("[ERROR]: No host or port specified.")
@@ -112,9 +116,9 @@ def process_segments(self, segments):
112116
for i, seg in enumerate(segments):
113117
if not text or text[-1] != seg["text"]:
114118
text.append(seg["text"])
115-
if i == len(segments) - 1 and not seg.get("completed", False):
119+
if i == len(segments) - 1:
116120
self.last_segment = seg
117-
elif (self.server_backend == "faster_whisper" and seg.get("completed", False) and
121+
elif (self.server_backend == "faster_whisper" and
118122
(not self.transcript or
119123
float(seg['start']) >= float(self.transcript[-1]['end']))):
120124
self.transcript.append(seg)
@@ -203,9 +207,7 @@ def on_open(self, ws):
203207
"language": self.language,
204208
"task": self.task,
205209
"model": self.model,
206-
"use_vad": self.use_vad,
207-
"max_clients": self.max_clients,
208-
"max_connection_time": self.max_connection_time,
210+
"use_vad": self.use_vad
209211
}
210212
)
211213
)
@@ -259,9 +261,7 @@ def write_srt_file(self, output_path="output.srt"):
259261
260262
"""
261263
if self.server_backend == "faster_whisper":
262-
if not self.transcript and self.last_segment is not None:
263-
self.transcript.append(self.last_segment)
264-
elif self.last_segment and self.transcript[-1]["text"] != self.last_segment["text"]:
264+
if (self.last_segment):
265265
self.transcript.append(self.last_segment)
266266
utils.create_srt_file(self.transcript, output_path)
267267

@@ -689,15 +689,8 @@ def __init__(
689689
output_recording_filename="./output_recording.wav",
690690
output_transcription_path="./output.srt",
691691
log_transcription=True,
692-
max_clients=4,
693-
max_connection_time=600,
694692
):
695-
self.client = Client(
696-
host, port, lang, translate, model, srt_file_path=output_transcription_path,
697-
use_vad=use_vad, log_transcription=log_transcription, max_clients=max_clients,
698-
max_connection_time=max_connection_time
699-
)
700-
693+
self.client = Client(host, port, lang, translate, model, srt_file_path=output_transcription_path, use_vad=use_vad, log_transcription=log_transcription)
701694
if save_output_recording and not output_recording_filename.endswith(".wav"):
702695
raise ValueError(f"Please provide a valid `output_recording_filename`: {output_recording_filename}")
703696
if not output_transcription_path.endswith(".srt"):

0 commit comments

Comments
 (0)