Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wyoming TCP server #52

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements_wyoming_api.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wyoming==1.4.1
Empty file.
190 changes: 190 additions & 0 deletions rhasspy3_wyoming_api/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import argparse
import asyncio
import logging
from functools import partial
from pathlib import Path

from wyoming.info import (
Attribution,
Info,
TtsProgram,
TtsVoice,
AsrProgram,
AsrModel,
WakeProgram,
WakeModel,
HandleProgram,
HandleModel,
IntentProgram,
IntentModel,
)
from wyoming.server import AsyncServer

from rhasspy3.core import Rhasspy

from .handler import PipelineEventHandler
from .process import PipelineProcessManager

_DIR = Path(__file__).parent
_LOGGER = logging.getLogger("rhasspy")


async def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"-c",
"--config",
default=_DIR.parent / "config",
help="Configuration directory",
)
parser.add_argument(
"--pipeline", default="default", help="Name of default pipeline to run"
)
parser.add_argument("--uri", default="stdio://", help="unix:// or tcp://")
parser.add_argument(
"--language",
default=["en"],
action="append",
help="Reported language (may be used repeatedly)",
)
parser.add_argument("--debug", action="store_true", help="Log DEBUG messages")
args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)

rhasspy = Rhasspy.load(args.config)
pipeline = rhasspy.config.pipelines[args.pipeline]

wyoming_info = Info(
tts=[] if pipeline.tts is None else [
TtsProgram(
name=pipeline.tts.name,
description=f"Rhasspy3 {args.pipeline} pipeline TTS program",
attribution=Attribution(
name="rhasspy", url="https://github.com/rhasspy/"
),
installed=True,
voices=[
TtsVoice(
name="default",
description="Pipeline-defined voice",
attribution=Attribution(
name="rhasspy", url="https://github.com/rhasspy"
),
installed=True,
languages=args.language,
)
],
)
],
asr=[] if pipeline.asr is None else [
AsrProgram(
name=pipeline.asr.name,
description=f"Rhasspy3 {args.pipeline} pipeline ASR program",
attribution=Attribution(
name="rhasspy", url="https://github.com/rhasspy/"
),
installed=True,
models=[
AsrModel(
name="default",
description="Pipeline-defined model",
attribution=Attribution(
name="rhasspy",
url="https://github.com/rhasspy/",
),
installed=True,
languages=args.language,
)
],
)
],
wake=[] if pipeline.wake is None else [
WakeProgram(
name=pipeline.wake.name,
description=f"Rhasspy3 {args.pipeline} pipeline wake program",
attribution=Attribution(
name="rhasspy", url="https://github.com/rhasspy/"
),
installed=True,
models=[
WakeModel(
name="default",
description="Pipeline-defined model",
attribution=Attribution(
name="rhasspy",
url="https://github.com/rhasspy/",
),
installed=True,
languages=args.language,
)
],
)
],
handle=[] if pipeline.handle is None else [
HandleProgram(
name=pipeline.handle.name,
description=f"Rhasspy3 {args.pipeline} pipeline handle program",
attribution=Attribution(
name="rhasspy", url="https://github.com/rhasspy/"
),
installed=True,
models=[
HandleModel(
name="default",
description="Pipeline-defined model",
attribution=Attribution(
name="rhasspy",
url="https://github.com/rhasspy/",
),
installed=True,
languages=args.language,
)
],
)
],
intent=[] if pipeline.intent is None else [
IntentProgram(
name=pipeline.intent.name,
description=f"Rhasspy3 {args.pipeline} pipeline intent program",
attribution=Attribution(
name="rhasspy", url="https://github.com/rhasspy/"
),
installed=True,
models=[
IntentModel(
name="default",
description="Pipeline-defined model",
attribution=Attribution(
name="rhasspy",
url="https://github.com/rhasspy/",
),
installed=True,
languages=args.language,
)
],
)
],
)

process_manager = PipelineProcessManager(rhasspy, pipeline)

# Start server
server = AsyncServer.from_uri(args.uri)

_LOGGER.info("Ready")
await server.run(
partial(
PipelineEventHandler,
wyoming_info,
process_manager,
)
)


# -----------------------------------------------------------------------------

if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass
Loading