Skip to content

CompletedText2Speech

trigger_completed_text2speech(sender, **kwargs)

After the text2speech is done, save it to the database

Parameters:

Name Type Description Default
sender

The sender of the signal

required
kwargs

The data passed to the signal

{}
Source code in API/orchestrator/chain/completed_text2speech.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@receiver(completed_text2speech)
def trigger_completed_text2speech(sender, **kwargs):
    """
    After the text2speech is done, save it to the database

    Args:
        sender: The sender of the signal
        kwargs: The data passed to the signal
    """
    logger.info("Text2Speech completed triggerred")
    try:
        data = kwargs.get("data", {})
        track_id = kwargs.get("track_id", None)
        logger.info(data)
        task_data = TaskData(**data)

        if track_id is None:
            logger.error("No track_id found")
            return
        # get the speech2text task based on the track_id
        speech2text_task = (
            Task.objects.filter(track_id=track_id, task_name="speech2text")
            .order_by("-created_at")
            .first()
        )
        if speech2text_task is None:
            logger.error("No speech2text task found")
            return
        text = speech2text_task.result_json["result_profile"].get("text", "")
        logger.info(text)
        logger.info(speech2text_task.parameters)
        text2speech_file = task_data.result_json["result_profile"].get(
            "audio_file_path", ""
        )
        data_multimodal_conversation_log_res_speech(
            task_data=task_data,
            speech_file_path=text2speech_file,
        )

    except Exception as e:
        logger.exception(e)
        return