60 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""
06_osc_receiver.py
Very simple OSC receiver demo.
It shows that different OSC addresses are mapped
to different handler functions.
"""
from pathlib import Path
from pythonosc.dispatcher import Dispatcher
from pythonosc.osc_server import BlockingOSCUDPServer
from piper_module import Narrator, Language, Quality, LLM
IP = "100.83.246.218"
PORT = 9001
def on_read(address, *args):
print(f"on_read() address={address} args={args}")
narrator.read(str(args[0]))
def on_write_story(address, *args):
print(f"on_write_story() address={address} args={args}")
story = narrator.write_story(str(args[0]), str(args[1]))
print(story)
def on_read_story(address, *args):
print(f"on_read_story() address={address} args={args}")
story = narrator.write_story(str(args[0]), str(args[1]))
narrator.read(story)
def main() -> None:
dispatcher = Dispatcher()
dispatcher.map("/read", on_read)
dispatcher.map("/write_story", on_write_story)
dispatcher.map("/read_story", on_read_story)
server = BlockingOSCUDPServer((IP, PORT), dispatcher)
global narrator
llm = LLM("qwen2.5-7b-instruct-1m","http://100.83.153.234:1234/api/v1/chat" )
narrator = Narrator(Language.de_DE, "thorsten", Path("C:\Interaktion\WerWolf\piper-voices"), llm)
print(f"Listening for OSC on {IP}:{PORT}")
print("Try sending:")
print(" /read")
print(" /write_story")
print(" /read_story")
server.serve_forever()
if __name__ == "__main__":
main()