GameSentenceMiner 2.5.6__py3-none-any.whl → 2.5.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- GameSentenceMiner/communication/__init__.py +22 -0
- GameSentenceMiner/communication/send.py +7 -0
- GameSentenceMiner/communication/websocket.py +77 -0
- {gamesentenceminer-2.5.6.dist-info → gamesentenceminer-2.5.7.dist-info}/METADATA +1 -1
- {gamesentenceminer-2.5.6.dist-info → gamesentenceminer-2.5.7.dist-info}/RECORD +9 -6
- {gamesentenceminer-2.5.6.dist-info → gamesentenceminer-2.5.7.dist-info}/WHEEL +0 -0
- {gamesentenceminer-2.5.6.dist-info → gamesentenceminer-2.5.7.dist-info}/entry_points.txt +0 -0
- {gamesentenceminer-2.5.6.dist-info → gamesentenceminer-2.5.7.dist-info}/licenses/LICENSE +0 -0
- {gamesentenceminer-2.5.6.dist-info → gamesentenceminer-2.5.7.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
import os.path
|
2
|
+
from dataclasses import dataclass, field
|
3
|
+
from typing import Dict, Optional, Any
|
4
|
+
|
5
|
+
from dataclasses_json import dataclass_json, Undefined
|
6
|
+
from websocket import WebSocket
|
7
|
+
|
8
|
+
from GameSentenceMiner.configuration import get_app_directory
|
9
|
+
|
10
|
+
CONFIG_FILE = os.path.join(get_app_directory(), "shared_config.json")
|
11
|
+
websocket: WebSocket = None
|
12
|
+
|
13
|
+
@dataclass_json(undefined=Undefined.RAISE)
|
14
|
+
@dataclass
|
15
|
+
class Message:
|
16
|
+
"""
|
17
|
+
Represents a message for inter-process communication.
|
18
|
+
Mimics the structure of IPC or HTTP calls.
|
19
|
+
"""
|
20
|
+
function: str
|
21
|
+
data: Dict[str, Any] = field(default_factory=dict)
|
22
|
+
id: Optional[str] = None
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import asyncio
|
2
|
+
import os.path
|
3
|
+
|
4
|
+
import websockets
|
5
|
+
import json
|
6
|
+
|
7
|
+
from websocket import WebSocket
|
8
|
+
|
9
|
+
from GameSentenceMiner.communication import Message
|
10
|
+
from GameSentenceMiner.configuration import get_app_directory, logger
|
11
|
+
|
12
|
+
CONFIG_FILE = os.path.join(get_app_directory(), "shared_config.json")
|
13
|
+
websocket: WebSocket = None
|
14
|
+
handle_websocket_message = None
|
15
|
+
|
16
|
+
async def do_websocket_connection(port):
|
17
|
+
"""
|
18
|
+
Connects to the WebSocket server running in the Electron app.
|
19
|
+
"""
|
20
|
+
global websocket
|
21
|
+
|
22
|
+
uri = f"ws://localhost:{port}" # Use the port from Electron
|
23
|
+
logger.debug(f"Electron Communication : Connecting to server at {uri}...")
|
24
|
+
try:
|
25
|
+
async with websockets.connect(uri) as websocket:
|
26
|
+
logger.debug(f"Connected to websocket server at {uri}")
|
27
|
+
|
28
|
+
# Send an initial message
|
29
|
+
message = Message(function="on_connect", data={"message": "Hello from Python!"})
|
30
|
+
await websocket.send(message.to_json())
|
31
|
+
logger.debug(f"> Sent: {message}")
|
32
|
+
|
33
|
+
# Receive messages from the server
|
34
|
+
while True:
|
35
|
+
try:
|
36
|
+
response = await websocket.recv()
|
37
|
+
if response is None:
|
38
|
+
break
|
39
|
+
logger.debug(f"Electron Communication : < Received: {response}")
|
40
|
+
handle_websocket_message(Message.from_json(response))
|
41
|
+
await asyncio.sleep(1) # keep the connection alive
|
42
|
+
except websockets.ConnectionClosedOK:
|
43
|
+
logger.debug("Electron Communication : Connection closed by server")
|
44
|
+
break
|
45
|
+
except websockets.ConnectionClosedError as e:
|
46
|
+
logger.debug(f"Electron Communication : Connection closed with error: {e}")
|
47
|
+
break
|
48
|
+
except ConnectionRefusedError:
|
49
|
+
logger.debug(f"Electron Communication : Error: Could not connect to server at {uri}. Electron App not running..")
|
50
|
+
except Exception as e:
|
51
|
+
logger.debug(f"Electron Communication : An error occurred: {e}")
|
52
|
+
|
53
|
+
def connect_websocket():
|
54
|
+
"""
|
55
|
+
Main function to run the WebSocket client.
|
56
|
+
"""
|
57
|
+
# Load the port from the same config.json the Electron app uses
|
58
|
+
try:
|
59
|
+
with open(CONFIG_FILE, "r") as f:
|
60
|
+
config = json.load(f)
|
61
|
+
port = config["port"]
|
62
|
+
except FileNotFoundError:
|
63
|
+
print("Error: shared_config.json not found. Using default port 8766. Ensure Electron app creates this file.")
|
64
|
+
port = 8766 # Default port, same as in Electron
|
65
|
+
except json.JSONDecodeError:
|
66
|
+
print("Error: shared_config.json was not valid JSON. Using default port 8765.")
|
67
|
+
port = 8766
|
68
|
+
|
69
|
+
asyncio.run(do_websocket_connection(port))
|
70
|
+
|
71
|
+
def register_websocket_message_handler(handler):
|
72
|
+
global handle_websocket_message
|
73
|
+
handle_websocket_message = handler
|
74
|
+
|
75
|
+
|
76
|
+
if __name__ == "__main__":
|
77
|
+
connect_websocket()
|
@@ -11,6 +11,9 @@ GameSentenceMiner/obs.py,sha256=N7XoPSzLk9rHi4sgsG_LS2dN06MrqwN2mpSHfjONTjE,7368
|
|
11
11
|
GameSentenceMiner/package.py,sha256=YlS6QRMuVlm6mdXx0rlXv9_3erTGS21jaP3PNNWfAH0,1250
|
12
12
|
GameSentenceMiner/util.py,sha256=tkaoU1bj8iPMTNwUCWUzFLAnT44Ot92D1tYwQMEnARw,7336
|
13
13
|
GameSentenceMiner/utility_gui.py,sha256=aVdI9zVXADS53g7QtTgmkVK1LumBsXF4Lou3qJzgHN8,7487
|
14
|
+
GameSentenceMiner/communication/__init__.py,sha256=_jGn9PJxtOAOPtJ2rI-Qu9hEHVZVpIvWlxKvqk91_zI,638
|
15
|
+
GameSentenceMiner/communication/send.py,sha256=oOJdCS6-LNX90amkRn5FL2xqx6THGm56zHR2ntVIFTE,229
|
16
|
+
GameSentenceMiner/communication/websocket.py,sha256=vrZ9KwRUyZOepjayJkxZZTsNIbHGcDLgDRO9dNDwizM,2914
|
14
17
|
GameSentenceMiner/downloader/Untitled_json.py,sha256=RUUl2bbbCpUDUUS0fP0tdvf5FngZ7ILdA_J5TFYAXUQ,15272
|
15
18
|
GameSentenceMiner/downloader/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
16
19
|
GameSentenceMiner/downloader/download_tools.py,sha256=mI1u_FGBmBqDIpCH3jOv8DOoZ3obgP5pIf9o9SVfX2Q,8131
|
@@ -18,9 +21,9 @@ GameSentenceMiner/vad/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3h
|
|
18
21
|
GameSentenceMiner/vad/silero_trim.py,sha256=-thDIZLuTLra3YBj7WR16Z6JeDgSpge2YuahprBvD8I,1585
|
19
22
|
GameSentenceMiner/vad/vosk_helper.py,sha256=BI_mg_qyrjNbuEJjXSUDoV0FWEtQtEOAPmrrNixnZ_8,5974
|
20
23
|
GameSentenceMiner/vad/whisper_helper.py,sha256=OF4J8TPPoKPJR1uFwrWAZ2Q7v0HJkVvNGmF8l1tACX0,3447
|
21
|
-
gamesentenceminer-2.5.
|
22
|
-
gamesentenceminer-2.5.
|
23
|
-
gamesentenceminer-2.5.
|
24
|
-
gamesentenceminer-2.5.
|
25
|
-
gamesentenceminer-2.5.
|
26
|
-
gamesentenceminer-2.5.
|
24
|
+
gamesentenceminer-2.5.7.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
25
|
+
gamesentenceminer-2.5.7.dist-info/METADATA,sha256=TVU0qDawh6UwnB9CD2y_zKATbvuVSVhTDKGjgPCRBLI,5435
|
26
|
+
gamesentenceminer-2.5.7.dist-info/WHEEL,sha256=DK49LOLCYiurdXXOXwGJm6U4DkHkg4lcxjhqwRa0CP4,91
|
27
|
+
gamesentenceminer-2.5.7.dist-info/entry_points.txt,sha256=2APEP25DbfjSxGeHtwBstMH8mulVhLkqF_b9bqzU6vQ,65
|
28
|
+
gamesentenceminer-2.5.7.dist-info/top_level.txt,sha256=V1hUY6xVSyUEohb0uDoN4UIE6rUZ_JYx8yMyPGX4PgQ,18
|
29
|
+
gamesentenceminer-2.5.7.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|