new osc, tempo, etc.

This commit is contained in:
NATURESPEAK
2022-04-10 15:20:13 +02:00
parent 5857da6e00
commit d70f643836
5 changed files with 622 additions and 88 deletions
+56
View File
@@ -0,0 +1,56 @@
from pythonosc import udp_client
from pythonosc import osc_server
from pythonosc import dispatcher
from threading import Lock
temp_mutex = Lock()
class OscBroadcaster:
def __init__(self, name: str, host: str, port: str, command_channel: str):
self.name = name
self.host = host
self.port = int(port)
self.cmd = command_channel
self.client = udp_client.SimpleUDPClient(self.host, self.port)
def utterance(self, utterance: str, channel: str):
self.client.send_message(channel, utterance)
def command(self, command: str):
self.client.send_message(self.cmd, command)
def temperature(self, temp: float, channel: str):
global temp_mutex
with temp_mutex:
self.client.send_message(self.cmd, command)
class OscReceiver:
def __init__(self, name: str, host: str, port: str, callback_fn_command=None, callback_fn_temp=None):
self.dispatcher = dispatcher.Dispatcher()
if callback_fn_command != None:
self.dispatcher.map('/command', callback_fn_command)
if callback_fn_temp != None:
self.dispatcher.map('/temperature', callback_fn_command)
self.name = name
self.host = "127.0.0.1"
self.port = int(port)
self.server = osc_server.ThreadingOSCUDPServer((self.host, self.port), self.dispatcher)
# # osc_udp_server(self.host, self.port, self.name)
# osc_udp_server("127.0.0.1", self.port, self.name)
# if callback_fn:
# osc_method('/', callback_fn)
# else:
# osc_method('/', temperature)
+4
View File
@@ -1,4 +1,5 @@
import string, regex
from gensim.utils import tokenize
def clean(text: str) -> str:
@@ -48,6 +49,9 @@ def fragments(utterance: str):
return frags
def tokenise(utterance: str):
return list(tokenize(utterance, lower=True))
+17 -12
View File
@@ -7,29 +7,32 @@ UTTERANCE_MEMORY_MIN_DIST = 0.2
class Voice:
def __init__(self, name: str, model: str, tokenizer: str, temp: int, lenght: int):
def __init__(self, name: str, model: str, tokenizer: str, temp: int, length: int):
self.name = name
self.temp = temp
self.lenght = lenght
self.length = length
self.v = aitextgen(model_folder=model, tokenizer_file=tokenizer)
self.utterances = []
def utter_n(self, n: int, temp: float = None, lenght: int = None):
def utter_n(self, n: int, temp: float = None, length: int = None):
t = self.temp if temp == None else temp
l = self.lenght if lenght == None else lenght
return self.v.generate(n=n, max_lenght=l, temperature=t, seed=int(time.time()), return_as_list=True)
l = self.length if length == None else length
return self.v.generate(n=n, max_length=l, temperature=t, seed=int(time.time()), return_as_list=True)
def utter_one(self, temp: int = None, lenght: float = None) -> str:
def utter_one(self, temp: float = None, length: int = None) -> str:
t = self.temp if temp == None else temp
l = self.lenght if lenght == None else lenght
return self.utter_n(n=1, temp=temp, lenght=lenght)[0]
l = self.length if length == None else length
return self.utter_n(n=1, temp=temp, length=length)[0]
def prompt(self, pinput: str, temp: float = None, length: int = None) -> str:
t = self.temp if temp == None else temp
l = self.length if length == None else length
return self.v.generate(prompt=pinput, n=1, max_length=l, temperature=t, seed=int(time.time()), return_as_list=True)[0]
def select(self, utterance: str) -> bool:
# fuction making sure to not say the same thing
print("select;")
toks = set(gensim.utils.tokenize(utterance))
i = 0
@@ -41,13 +44,15 @@ class Voice:
self.utterances.append(toks)
print(len(self.utterances))
if len(self.utterances) > UTTERANCE_MEMORY_LEN:
self.utterances.pop(0)
return True
def remember(self, utterance: str):
toks = set(gensim.utils.tokenize(utterance))
self.utterances.append(toks)
def set_channel(self, root: str, endpoint: str):
self.channel = root + endpoint