Beispiel #1
0
    def save(self, savepath):
        turns = self.memory.finalize_turns()

        states = []
        for state in self.dialog_states[1:]:  # dont care about dummy start state
            state["time"] -= self.start_time
            states.append(state)

        # ommitted
        omitted_turns = []
        for turn in self.agent_omitted:
            turn.norm_time(self.memory.start_time)
            omitted_turns.append(turn.to_dict())
        data = {
            "turns": turns,
            "omitted_agent_turns": omitted_turns,
            "vad_ipu_on": list(np.array(self.vad_ipu_on) - self.start_time),
            "vad_ipu_off": list(np.array(self.vad_ipu_off) - self.start_time),
            "vad_turn_on": list(np.array(self.vad_turn_on) - self.start_time),
            "vad_turn_off": list(np.array(self.vad_turn_off) - self.start_time),
            "asr_on": list(np.array(self.asr_on) - self.start_time),
            "asr_off": list(np.array(self.asr_off) - self.start_time),
            "agent_turn_on": list(np.array(self.agent_turn_on) - self.start_time),
            "agent_turn_off": list(np.array(self.agent_turn_off) - self.start_time),
            "agent_interrupted": list(
                np.array(self.agent_interrupted) - self.start_time
            ),
            "dialog_states": states,
        }

        dirpath = split(savepath)[0]
        if dirpath != "":
            makedirs(dirpath, exist_ok=True)
        write_json(data, savepath)
        print("Saved memory -> ", savepath)
Beispiel #2
0
    def save(self, savepath):
        data = self.finalize_turns()

        dirpath = split(savepath)[0]
        if dirpath != "":
            makedirs(dirpath, exist_ok=True)
        write_json(data, savepath)
        print("Saved memory -> ", savepath)
Beispiel #3
0
def try_it():
    N = 18
    experiment = sample_experiment(N, sessions=SESSIONS3)
    sanity_check(experiment)
    experiment = to_named(experiment, dialogs3, policies3)
    sanity_check(experiment)

    filename = "/tmp/experiment.json"
    write_json(experiment, filename)

    N = 18
    experiment = sample_experiment(N, sessions=SESSIONS2)
    sanity_check(experiment)
    experiment = to_named(experiment, dialogs2, policies2)
    sanity_check(experiment)

    filename = "./experiment/experiment2.json"
    write_json(experiment, filename)
Beispiel #4
0
    def process_iu(self, input_iu):
        output_iu = self.create_iu(input_iu)
        if input_iu.get_text() != "":
            text = input_iu.get_text()

            cache_file = join(self.cache_dir, "_".join(text.split()) + ".wav")
            if exists(cache_file):
                # print("Using Cache TTS")
                raw_audio, _ = self.read_audio(cache_file)
                info = read_json(cache_file.replace(".wav", ".json"))
                words = info["words"]
                starts = info["starts"]
                ends = info["ends"]
                duration = info["duration"]
            else:
                words, starts, ends, duration, raw_audio = self.tts.tts(
                    input_iu.get_text())
                # print("SAVE Cache TTS")
                self.write_audio(raw_audio, cache_file)
                if self.sample_rate != self.polly_sample_rate:
                    print("RESAMPLE Cache TTS")
                    raw_audio = self.resample_sox(cache_file)
                write_json(
                    {
                        "words": words,
                        "starts": starts,
                        "ends": ends,
                        "duration": duration,
                    },
                    cache_file.replace(".wav", ".json"),
                )

            # if self.record:
            #     _ = self.save_audio_file(raw_audio, words)

            nframes = len(raw_audio) / self.bytes_per_sample
            output_iu.set_audio(raw_audio, nframes, self.sample_rate,
                                self.bytes_per_sample)
            output_iu.words = words
            output_iu.starts = starts
            output_iu.ends = ends
            output_iu.duration = duration
        output_iu.dispatch = input_iu.dispatch
        return output_iu
Beispiel #5
0
    def save_hyperparameters(self):
        hparams = {
            "policy": self.policy,
            "dm_type": self.dm_type,
            "task": self.task,
            "chunk_time": self.chunk_time,
            "sample_rate": self.sample_rate,
            "bytes_per_sample": self.bytes_per_sample,
            "speech_chunk_time": self.speech_chunk_time,
            "speech_sample_rate": self.speech_sample_rate,
            "fallback_duration": self.fallback_duration,
            "backchannel_prob": self.backchannel_prob,
            "trp": self.trp,
            "verbose": self.verbose,
            "bypass": self.bypass,
            "date": datetime.now().strftime("%Y-%m-%d_%H:%M"),
        }

        savepath = join(self.session_dir, "hparams.json")
        write_json(hparams, savepath)
        print("Saved hparams -> ", savepath)
Beispiel #6
0
    parser = ArgumentParser()
    parser.add_argument("-N",
                        "--n_participants",
                        type=int,
                        help="Number of participants")
    parser.add_argument(
        "--not_named",
        action="store_true",
        help="Get back A,B,C and X,Y,Z instead of names of dialog/policies",
    )
    parser.add_argument(
        "--filename",
        type=str,
        default=None,
        help="filename to store json file of experiment",
    )
    args = parser.parse_args()
    print(args)

    experiment = sample_experiment(args.n_participants, sessions=SESSIONS2)
    sanity_check(experiment)

    if not args.not_named:
        experiment = to_named(experiment, dialogs=dialogs2, policies=policies2)
        print("\n" + "=" * 70)
        sanity_check(experiment)

    if args.filename is not None:
        write_json(experiment, args.filename)
        print("Saved json file -> ", args.filename)