Skip to content

Commit

Permalink
write srt file only for faster_whisper backend
Browse files Browse the repository at this point in the history
  • Loading branch information
makaveli10 committed Feb 1, 2024
1 parent f590446 commit 08575a0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 13 additions & 5 deletions whisper_live/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def on_message(self, ws, message):

if "message" in message.keys() and message["message"] == "SERVER_READY":
self.recording = True
self.server_backend = message["backend"]
print(f"[INFO]: Server Running with backend {self.server_backend}")
return

if "language" in message.keys():
Expand All @@ -218,7 +220,7 @@ def on_message(self, ws, message):

if i == n_segments-1:
self.last_segment = seg
else:
elif self.server_backend == "faster_whisper":
if not len(self.transcript) or float(seg['start']) >= float(self.transcript[-1]['end']):
self.transcript.append(seg)

Expand Down Expand Up @@ -337,7 +339,9 @@ def play_file(self, filename):
assert self.last_response_recieved
while time.time() - self.last_response_recieved < self.disconnect_if_no_response_for:
continue
self.write_srt_file(self.srt_file_path)

if self.server_backend == "faster_whisper":
self.write_srt_file(self.srt_file_path)
self.stream.close()
self.close_websocket()

Expand All @@ -347,7 +351,8 @@ def play_file(self, filename):
self.stream.close()
self.p.terminate()
self.close_websocket()
self.write_srt_file(self.srt_file_path)
if self.server_backend == "faster_whisper":
self.write_srt_file(self.srt_file_path)
print("[INFO]: Keyboard interrupt.")

def close_websocket(self):
Expand Down Expand Up @@ -475,7 +480,8 @@ def record(self, out_file="output_recording.wav"):
t.start()
n_audio_file += 1
self.frames = b""
self.write_srt_file(self.srt_file_path)
if self.server_backend == "faster_whisper":
self.write_srt_file(self.srt_file_path)

except KeyboardInterrupt:
if len(self.frames):
Expand All @@ -489,7 +495,8 @@ def record(self, out_file="output_recording.wav"):
self.close_websocket()

self.write_output_recording(n_audio_file, out_file)
self.write_srt_file(self.srt_file_path)
if self.server_backend == "faster_whisper":
self.write_srt_file(self.srt_file_path)

def write_output_recording(self, n_audio_file, out_file):
"""
Expand Down Expand Up @@ -530,6 +537,7 @@ def write_srt_file(self, output_path="output.srt"):
self.transcript.append(self.last_segment)
create_srt_file(self.transcript, output_path)


class TranscriptionClient:
"""
Client for handling audio transcription tasks via a WebSocket connection.
Expand Down
6 changes: 4 additions & 2 deletions whisper_live/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ def __init__(
json.dumps(
{
"uid": self.client_uid,
"message": self.SERVER_READY
"message": self.SERVER_READY,
"backend": "tensorrt"
}
)
)
Expand Down Expand Up @@ -615,7 +616,8 @@ def __init__(
json.dumps(
{
"uid": self.client_uid,
"message": self.SERVER_READY
"message": self.SERVER_READY,
"backend": "faster_whisper"
}
)
)
Expand Down

0 comments on commit 08575a0

Please sign in to comment.