Spaces:
Paused
Paused
makaveli10
commited on
Commit
•
456c9bb
1
Parent(s):
a291214
add whisper bot client
Browse files- whisper_live/__version__.py +0 -1
- whisper_live/client.py +27 -12
whisper_live/__version__.py
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
__version__="0.0.9"
|
|
|
|
whisper_live/client.py
CHANGED
@@ -50,7 +50,7 @@ class Client:
|
|
50 |
INSTANCES = {}
|
51 |
|
52 |
def __init__(
|
53 |
-
self, host=None, port=None, is_multilingual=False, lang=None, translate=False
|
54 |
):
|
55 |
"""
|
56 |
Initializes a Client instance for audio recording and streaming to a server.
|
@@ -66,7 +66,7 @@ class Client:
|
|
66 |
lang (str, optional): The selected language for transcription when multilingual is disabled. Default is None.
|
67 |
translate (bool, optional): Specifies if the task is translation. Default is False.
|
68 |
"""
|
69 |
-
self.chunk = 1024
|
70 |
self.format = pyaudio.paInt16
|
71 |
self.channels = 1
|
72 |
self.rate = 16000
|
@@ -80,7 +80,9 @@ class Client:
|
|
80 |
self.last_response_recieved = None
|
81 |
self.disconnect_if_no_response_for = 15
|
82 |
self.multilingual = is_multilingual
|
83 |
-
self.language = lang
|
|
|
|
|
84 |
if translate:
|
85 |
self.task = "translate"
|
86 |
|
@@ -140,11 +142,16 @@ class Client:
|
|
140 |
print("[ERROR]: invalid client uid")
|
141 |
return
|
142 |
|
143 |
-
if "status" in message.keys()
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
if "message" in message.keys() and message["message"] == "DISCONNECT":
|
150 |
print("[INFO]: Server overtime disconnected.")
|
@@ -162,11 +169,18 @@ class Client:
|
|
162 |
)
|
163 |
return
|
164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
if "segments" not in message.keys():
|
166 |
return
|
167 |
|
168 |
message = message["segments"]
|
169 |
text = []
|
|
|
170 |
if len(message):
|
171 |
for seg in message:
|
172 |
if text and text[-1] == seg["text"]:
|
@@ -213,6 +227,7 @@ class Client:
|
|
213 |
"multilingual": self.multilingual,
|
214 |
"language": self.language,
|
215 |
"task": self.task,
|
|
|
216 |
}
|
217 |
)
|
218 |
)
|
@@ -497,8 +512,8 @@ class TranscriptionClient:
|
|
497 |
transcription_client()
|
498 |
```
|
499 |
"""
|
500 |
-
def __init__(self, host, port, is_multilingual=False, lang=None, translate=False):
|
501 |
-
self.client = Client(host, port, is_multilingual, lang, translate)
|
502 |
|
503 |
def __call__(self, audio=None, hls_url=None):
|
504 |
"""
|
@@ -514,10 +529,10 @@ class TranscriptionClient:
|
|
514 |
"""
|
515 |
print("[INFO]: Waiting for server ready ...")
|
516 |
while not self.client.recording:
|
517 |
-
if self.client.waiting:
|
518 |
self.client.close_websocket()
|
519 |
return
|
520 |
-
|
521 |
print("[INFO]: Server Ready!")
|
522 |
if hls_url is not None:
|
523 |
self.client.process_hls_stream(hls_url)
|
|
|
50 |
INSTANCES = {}
|
51 |
|
52 |
def __init__(
|
53 |
+
self, host=None, port=None, is_multilingual=False, lang=None, translate=False, model_size="small"
|
54 |
):
|
55 |
"""
|
56 |
Initializes a Client instance for audio recording and streaming to a server.
|
|
|
66 |
lang (str, optional): The selected language for transcription when multilingual is disabled. Default is None.
|
67 |
translate (bool, optional): Specifies if the task is translation. Default is False.
|
68 |
"""
|
69 |
+
self.chunk = 1024 * 3
|
70 |
self.format = pyaudio.paInt16
|
71 |
self.channels = 1
|
72 |
self.rate = 16000
|
|
|
80 |
self.last_response_recieved = None
|
81 |
self.disconnect_if_no_response_for = 15
|
82 |
self.multilingual = is_multilingual
|
83 |
+
self.language = lang
|
84 |
+
self.model_size = model_size
|
85 |
+
self.server_error = False
|
86 |
if translate:
|
87 |
self.task = "translate"
|
88 |
|
|
|
142 |
print("[ERROR]: invalid client uid")
|
143 |
return
|
144 |
|
145 |
+
if "status" in message.keys():
|
146 |
+
if message["status"] == "WAIT":
|
147 |
+
self.waiting = True
|
148 |
+
print(
|
149 |
+
f"[INFO]:Server is full. Estimated wait time {round(message['message'])} minutes."
|
150 |
+
)
|
151 |
+
elif message["status"] == "ERROR":
|
152 |
+
print(f"Message from Server: {message['message']}")
|
153 |
+
self.server_error = True
|
154 |
+
return
|
155 |
|
156 |
if "message" in message.keys() and message["message"] == "DISCONNECT":
|
157 |
print("[INFO]: Server overtime disconnected.")
|
|
|
169 |
)
|
170 |
return
|
171 |
|
172 |
+
if "llm_output" in message.keys():
|
173 |
+
print("LLM output: ")
|
174 |
+
for item in message["llm_output"]:
|
175 |
+
print(item)
|
176 |
+
|
177 |
+
|
178 |
if "segments" not in message.keys():
|
179 |
return
|
180 |
|
181 |
message = message["segments"]
|
182 |
text = []
|
183 |
+
print(message)
|
184 |
if len(message):
|
185 |
for seg in message:
|
186 |
if text and text[-1] == seg["text"]:
|
|
|
227 |
"multilingual": self.multilingual,
|
228 |
"language": self.language,
|
229 |
"task": self.task,
|
230 |
+
"model_size": self.model_size,
|
231 |
}
|
232 |
)
|
233 |
)
|
|
|
512 |
transcription_client()
|
513 |
```
|
514 |
"""
|
515 |
+
def __init__(self, host, port, is_multilingual=False, lang=None, translate=False, model_size="small"):
|
516 |
+
self.client = Client(host, port, is_multilingual, lang, translate, model_size)
|
517 |
|
518 |
def __call__(self, audio=None, hls_url=None):
|
519 |
"""
|
|
|
529 |
"""
|
530 |
print("[INFO]: Waiting for server ready ...")
|
531 |
while not self.client.recording:
|
532 |
+
if self.client.waiting or self.client.server_error:
|
533 |
self.client.close_websocket()
|
534 |
return
|
535 |
+
|
536 |
print("[INFO]: Server Ready!")
|
537 |
if hls_url is not None:
|
538 |
self.client.process_hls_stream(hls_url)
|