Skip to content

Commit

Permalink
Make sip configuration optional.
Browse files Browse the repository at this point in the history
Add live_translator_precache mode, which is when enabled causes
only models to be loaded.
  • Loading branch information
sobomax committed Jul 18, 2024
1 parent 6ff56b7 commit 1db2d63
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
14 changes: 14 additions & 0 deletions Apps/LiveTranslator/LTActor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ def start(self, lt_prof: 'LTProfile', sip_actr:InfernSIPActor):
ray.get(futs)
self.sessions = {}

def precache(self, lt_prof: 'LTProfile'):
nltk.download('punkt')
lt_actr = ray.get_runtime_context().current_actor
tts_actrs = dict((l, InfernTTSActor.remote()) for l in lt_prof.tts_langs)
stt_actr = InfernSTTActor.remote()
futs = [_a.start.remote(**_k) for _a, _k in ((stt_actr, {}),) +
tuple((a, {'lang':l, 'output_sr':8000, 'device':'cpu'}) for l, a in tts_actrs.items())]
translators = [ntw_filter if _sol == _tl else
IG.get_translator(_sol, _tl, filter=partial(ntw_filter, obj=NumbersToWords(_tl))).translate
for _tl, _sol in zip(lt_prof.tts_langs, self.stt_out_langs)]
ray.get(futs)
for a in list(tts_actrs.values()) + [stt_actr]:
ray.get(a.stop.remote())

def new_sip_session_received(self, new_sess:RemoteSessionOffer):
if self.vds is None:
self.vds = VADSignals()
Expand Down
17 changes: 12 additions & 5 deletions Apps/LiveTranslator/LTProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@ class LTProfile():
outbound_conn: 'InfernSIPProfile'
outbount_params: str
actor: Optional[LTActor] = None
precache: bool

def __init__(self, name, conf):
def __init__(self, name, conf, precache):
self.name = name
self.tts_langs = tuple(conf['tts_langs'])
self.stt_langs = tuple(conf['stt_langs'])
self._outbound = conf['outbound']
if not precache:
self._outbound = conf['outbound']
self.precache = precache

def finalize(self, iconf:'InfernConfig'):
sip_cname, params = self._outbound.split(';', 1)
self.outbound_conn = iconf.connectors[sip_cname]
self.outbount_params = params
if not self.precache:
sip_cname, params = self._outbound.split(';', 1)
self.outbound_conn = iconf.connectors[sip_cname]
self.outbount_params = params
else:
actor = LTActor.remote()
res = ray.get(actor.precache.remote(self))

def getActor(self, iconf:'InfernConfig', sip_act:InfernSIPActor):
if self.actor is None:
Expand Down
22 changes: 15 additions & 7 deletions Core/InfernConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def validate_port_range(field, value, error):
}
}
}
}
},
'live_translator_precache': {'type': 'boolean'},
}
}
}
Expand Down Expand Up @@ -104,12 +105,19 @@ def __init__(self, filename: str):
port = int(bind[1]) if len(bind) == 2 else self.sip_conf.lport
self.sip_conf.laddr = bind[0]
self.sip_conf.lport = port
self.connectors = dict((f'sip/{name}', InfernSIPProfile(name, conf))
for name, conf in d['sip']['profiles'].items())
self.apps = dict((f'apps/live_translator/{name}', LTProfile(name, conf))
try:
self.connectors = dict((f'sip/{name}', InfernSIPProfile(name, conf))
for name, conf in d['sip']['profiles'].items())
except KeyError:
self.connectors = {}
precache = 'live_translator_precache' in d['apps'] and d['apps']['live_translator_precache']
self.apps = dict((f'apps/live_translator/{name}', LTProfile(name, conf, precache))
for name, conf in d['apps']['live_translator']['profiles'].items())
for app in self.apps.values():
app.finalize(self)
self.sip_actr = InfernSIPActor.options(max_concurrency=2).remote()
for conn in self.connectors.values():
conn.finalize(self.sip_actr, self)
if 'sip' in d:
self.sip_actr = InfernSIPActor.options(max_concurrency=2).remote()
for conn in self.connectors.values():
conn.finalize(self.sip_actr, self)
else:
self.sip_actr = None

0 comments on commit 1db2d63

Please sign in to comment.