Compare commits

...

2 Commits

Author SHA1 Message Date
4aa5466597 chore: bump version to 0.4.0
All checks were successful
Build and Publish / build-and-publish (push) Successful in 24s
Signed-off-by: Max P. <Mail@MPassarello.de>
2025-04-30 15:44:48 +02:00
495452f7bd feat(pyvtt): add support for optional preset in commands
- Add `preset` argument to `send_cmd` for passing optional presets.
- Modify command formatting to include preset if provided.
- Update CLI to accept an optional `preset` argument.
- Extend socket listener to parse and validate preset values.
- Enhance functionality to allow preset-based dynamic behavior.

Signed-off-by: Max P. <Mail@MPassarello.de>
2025-04-30 15:44:35 +02:00
3 changed files with 25 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
[project] [project]
name = "pyvtt" name = "pyvtt"
version = "0.3.3" version = "0.4.0"
description = "Python Voice to Text + LLMA" description = "Python Voice to Text + LLMA"
authors = [{ name = "Max P.", email = "Mail@MPassarello.de" }] authors = [{ name = "Max P.", email = "Mail@MPassarello.de" }]
license = { text = "MIT" } license = { text = "MIT" }

View File

@@ -2,10 +2,12 @@ import socket
import sys import sys
import argparse import argparse
from pyvtt.configuration import read_configurations from pyvtt.configuration import read_configurations
from typing import Optional
CONFIGURATION = read_configurations() CONFIGURATION = read_configurations()
def send_cmd(cmd: str, socket_path: str):
def send_cmd(cmd: str, socket_path: str, preset: Optional[str] = None) -> None:
""" """
Sends a command to a Unix domain socket server. Sends a command to a Unix domain socket server.
@@ -26,6 +28,8 @@ def send_cmd(cmd: str, socket_path: str):
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client: with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client:
client.settimeout(3) client.settimeout(3)
client.connect(socket_path) client.connect(socket_path)
if preset:
cmd = f"{cmd}::::{preset}"
client.sendall(cmd.encode()) client.sendall(cmd.encode())
except FileNotFoundError: except FileNotFoundError:
print(f"Error: The socket file '{socket_path}' does not exist.", file=sys.stderr, flush=True) print(f"Error: The socket file '{socket_path}' does not exist.", file=sys.stderr, flush=True)
@@ -47,6 +51,15 @@ def main():
default="toggle", default="toggle",
help="The command to send to the server (default: toggle).", help="The command to send to the server (default: toggle).",
) )
parser.add_argument(
"preset",
nargs="?",
default=None,
help="The preset to use (optional)."
)
args = parser.parse_args() args = parser.parse_args()
send_cmd(args.command, CONFIGURATION["socket_path"]) send_cmd(args.command, CONFIGURATION["socket_path"], args.preset)

View File

@@ -166,6 +166,15 @@ class SocketListener(threading.Thread):
conn, _ = self.sock.accept() conn, _ = self.sock.accept()
with conn: with conn:
data = conn.recv(1024).decode().strip() data = conn.recv(1024).decode().strip()
if data:
cmd = data.split("::::")
if len(cmd) > 1:
data = cmd[0]
preset = cmd[1]
if preset in [p["name"] for p in CONFIGURATION["presets"]]:
self.tray_app.set_preset([p["name"] for p in CONFIGURATION["presets"]].index(preset))
else:
data = cmd[0]
if data == "toggle": if data == "toggle":
self.tray_app.toggle_recording() self.tray_app.toggle_recording()
elif data == "start": elif data == "start":