rhasspy / rhasspy3

An open source voice assistant toolkit for many human languages
MIT License
311 stars 26 forks source link

Wyoming source repository #22

Closed mweinelt closed 1 year ago

mweinelt commented 1 year ago

Hi, I'm wondering where I can find the source repository for the wyoming package, that is up on PyPi.

The homepage points to this repository, and the structure looks similar to the rhasspy3 directory in this repository, but the code is different.

Also, is the code open for contributions?

mweinelt commented 1 year ago

I would very much like to submit the following change against the current wyoming release.


From: Martin Weinelt <hexa@darmstadt.ccc.de>
Date: Wed, 12 Jul 2023 19:05:54 +0200
Subject: [PATCH] Use urlparse for uri parsing in server component

Python's builtin urlparsing functionality has fewer edge cases, like
most home-grown url parsing code.

This change allows me to bind a wyoming server to an IPv6 socket.
---
 wyoming/server.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/wyoming/server.py b/wyoming/server.py
index 6dcc4e3..f3905b9 100644
--- a/wyoming/server.py
+++ b/wyoming/server.py
@@ -4,6 +4,7 @@ from abc import ABC, abstractmethod
 from functools import partial
 from pathlib import Path
 from typing import Callable, Set, Union
+from urllib.parser import urlparse

 from .event import Event, async_get_stdin, async_read_event, async_write_event

@@ -57,16 +58,15 @@ class AsyncServer(ABC):

     @staticmethod
     def from_uri(uri: str) -> "AsyncServer":
-        if uri.startswith("unix://"):
-            socket_path = uri[len("unix://") :]
-            return AsyncUnixServer(socket_path)
+        result = urlparse(uri)

-        if uri.startswith("tcp://"):
-            host, port_str = uri[len("tcp://") :].split(":")
-            port = int(port_str)
-            return AsyncTcpServer(host, port)
+        if result.scheme == "unix":
+            return AsyncUnixServer(result.path)

-        if uri.startswith("stdio://"):
+        if result.scheme == "tcp":
+            return AsyncTcpServer(result.hostname, result.port)
+
+        if result.scheme == "stdio":
             return AsyncStdioServer()

         raise ValueError("Only 'stdio://', 'unix://', or 'tcp://' are supported")
-- 
2.41.0
synesthesiam commented 1 year ago

Thanks, I can add this! The code is indeed in rhasspy3 but I haven't pushed it up just yet. I'm making a lot of changes quickly, so I don't want to break anyone depending on the Github repo just yet :smile:

synesthesiam commented 1 year ago

I pushed the code up to a side branch for now: https://github.com/rhasspy/rhasspy3/tree/wyoming-v1

KeithSBB commented 1 year ago

Thanks Michael,

I hope this branch leads to being able to setup Rhasspy 3 as a satellite speaker for Home Assistant.

synesthesiam commented 1 year ago

@KeithSBB Yep, that's what a lot of the new code is for :slightly_smiling_face: