Skip to content

Commit

Permalink
chore(): remove on_init/on_deinit
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinexcode committed Aug 5, 2024
1 parent 166b037 commit d2e35cc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,6 @@ def process_text_queue(self, rte: RteEnv):

@register_addon_as_extension("elevenlabs_tts_python")
class ElevenlabsTTSExtensionAddon(Addon):
def on_init(self, rte: RteEnv, manifest, property) -> None:
logger.info("on_init")
rte.on_init_done(manifest, property)
return

def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None:
logger.info("on_create_instance")
rte.on_create_instance_done(ElevenlabsTTSExtension(addon_name), context)

def on_deinit(self, rte: RteEnv) -> None:
logger.info("on_deinit")
rte.on_deinit_done()
return
Original file line number Diff line number Diff line change
Expand Up @@ -369,28 +369,9 @@ def chat_completions_stream_worker(start_time, input_text, memory):
)
thread.start()
logger.info(f"OpenAIChatGPTExtension on_data end")
# try:
# rte_data = Data.create("text_data")
# rte_data.set_property_string("text", "hello, world, who are you!")
# except Exception as e:
# logger.info(f"on_data new_data error, ", e)
# return

# rte.send_data(rte_data)


@register_addon_as_extension("openai_chatgpt_python")
class OpenAIChatGPTExtensionAddon(Addon):
def on_init(self, rte: RteEnv, manifest, property) -> None:
logger.info("OpenAIChatGPTExtensionAddon on_init")
rte.on_init_done(manifest, property)
return

def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None:
logger.info("on_create_instance")
rte.on_create_instance_done(OpenAIChatGPTExtension(addon_name), context)

def on_deinit(self, rte: RteEnv) -> None:
logger.info("OpenAIChatGPTExtensionAddon on_deinit")
rte.on_deinit_done()
return
24 changes: 5 additions & 19 deletions agents/addon/extension/polly_tts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def on_start(self, rte: Rte) -> None:

polly_config = PollyConfig.default_config()

for optional_param in [PROPERTY_REGION, PROPERTY_ENGINE, PROPERTY_VOICE,
PROPERTY_SAMPLE_RATE, PROPERTY_LANG_CODE,
for optional_param in [PROPERTY_REGION, PROPERTY_ENGINE, PROPERTY_VOICE,
PROPERTY_SAMPLE_RATE, PROPERTY_LANG_CODE,
PROPERTY_ACCESS_KEY, PROPERTY_SECRET_KEY ]:
try:
value = rte.get_property_string(optional_param).strip()
Expand All @@ -80,22 +80,18 @@ def on_stop(self, rte: Rte) -> None:
self.thread.join()
rte.on_stop_done()

def on_deinit(self, rte: Rte) -> None:
logger.info("PollyTTSExtension on_deinit")
rte.on_deinit_done()

def need_interrupt(self, ts: datetime.time) -> bool:
return (self.outdateTs - ts).total_seconds() > 1


def __get_frame(self, data: bytes) -> PcmFrame:
sample_rate = int(self.polly.config.sample_rate)

f = PcmFrame.create("pcm_frame")
f.set_sample_rate(sample_rate)
f.set_bytes_per_sample(2)
f.set_number_of_channels(1)

f.set_data_fmt(RTE_PCM_FRAME_DATA_FMT.RTE_PCM_FRAME_DATA_FMT_INTERLEAVE)
f.set_samples_per_channel(sample_rate // 100)
f.alloc_buf(self.frame_size)
Expand Down Expand Up @@ -142,7 +138,7 @@ def on_data(self, rte: Rte, data: Data) -> None:
if len(inputText) == 0:
logger.info("ignore empty text")
return

is_end = data.get_property_bool("end_of_segment")

logger.info("on data %s %d", inputText, is_end)
Expand All @@ -168,16 +164,6 @@ def on_cmd(self, rte: Rte, cmd: Cmd) -> None:

@register_addon_as_extension("polly_tts")
class PollyTTSExtensionAddon(Addon):
def on_init(self, rte: Rte, manifest, property) -> None:
logger.info("PollyTTSExtensionAddon on_init")
rte.on_init_done(manifest, property)
return

def on_create_instance(self, rte: Rte, addon_name: str, context) -> None:
logger.info("on_create_instance")
rte.on_create_instance_done(PollyTTSExtension(addon_name), context)

def on_deinit(self, rte: Rte) -> None:
logger.info("PollyTTSExtensionAddon on_deinit")
rte.on_deinit_done()
return

0 comments on commit d2e35cc

Please sign in to comment.