コード例 #1
0
ファイル: server.py プロジェクト: JoeTnC/xVA-Synth
    def do_POST(self):
        post_data = ""
        try:
            global fastpitch_model
            logger.info("POST {}".format(self.path))

            content_length = int(self.headers['Content-Length'])
            post_data = json.loads(self.rfile.read(content_length).decode('utf-8'))
            req_response = "POST request for {}".format(self.path)

            print("POST")
            print(self.path)
            logger.info(post_data)

            if self.path == "/setMode":
                hifi_gan = post_data["hifi_gan"]=="qnd"
                user_settings["hifi_gan"] = hifi_gan
                write_settings()

                if not hifi_gan and fastpitch_model.waveglow is None:
                    use_gpu = user_settings["use_gpu"]=="True"
                    fastpitch_model = fastpitch.init_waveglow(use_gpu, fastpitch_model)

            if self.path == "/setDevice":
                use_gpu = post_data["device"]=="gpu"
                setDevice(use_gpu)

                user_settings["use_gpu"] = use_gpu
                write_settings()

            if self.path == "/loadModel":
                ckpt = post_data["model"]
                fastpitch_model = fastpitch.loadModel(fastpitch_model, ckpt=ckpt, n_speakers=post_data["model_speakers"], device=fastpitch_model.device)

            if self.path == "/synthesize":
                text = post_data["sequence"]
                out_path = post_data["outfile"]
                pitch = post_data["pitch"] if "pitch" in post_data else None
                duration = post_data["duration"] if "duration" in post_data else None
                speaker_i = post_data["speaker_i"]
                hifi_gan = post_data["hifi_gan"] if "hifi_gan" in post_data else False
                pitch_data = [pitch, duration]

                req_response = fastpitch.infer(user_settings, text, out_path, fastpitch=fastpitch_model, hifi_gan=hifi_gan, speaker_i=speaker_i, pitch_data=pitch_data)

            if self.path == "/outputAudio":
                input_path = post_data["input_path"]
                output_path = post_data["output_path"]
                options = json.loads(post_data["options"])
                req_response = run_audio_post(logger, input_path, output_path, options)


            self._set_response()
            logger.info("req_response")
            logger.info(req_response)
            self.wfile.write(req_response.encode("utf-8"))
        except Exception as e:
            with open("./DEBUG_request.txt", "w+") as f:
                f.write(traceback.format_exc())
                f.write(str(post_data))
            logger.info("Post Error:\n {}".format(repr(e)))
            print(traceback.format_exc())
            logger.info(traceback.format_exc())
コード例 #2
0
    def do_POST(self):
        post_data = ""
        try:
            global fastpitch_model
            logger.info("POST {}".format(self.path))

            content_length = int(self.headers['Content-Length'])
            post_data = json.loads(self.rfile.read(content_length).decode('utf-8'))
            req_response = "POST request for {}".format(self.path)

            print("POST")
            print(self.path)
            logger.info(post_data)

            if self.path == "/setVocoder":
                vocoder = post_data["vocoder"]
                user_settings["vocoder"] = vocoder
                hifi_gan = "waveglow" not in vocoder
                write_settings()

                if vocoder not in ["qnd", "256_waveglow", "big_waveglow"]:
                    use_gpu = user_settings["use_gpu"]
                    fastpitch_model = fastpitch.init_hifigan(PROD, fastpitch_model, use_gpu, vocoder)

                if not hifi_gan:
                    use_gpu = user_settings["use_gpu"]
                    fastpitch_model = fastpitch.init_waveglow(use_gpu, fastpitch_model, vocoder, logger)

            if self.path == "/setDevice":
                use_gpu = post_data["device"]=="gpu"
                setDevice(use_gpu)

                user_settings["use_gpu"] = use_gpu
                write_settings()

            if self.path == "/loadModel":
                ckpt = post_data["model"]
                n_speakers = post_data["model_speakers"] if "model_speakers" in post_data else None
                fastpitch_model = fastpitch.loadModel(fastpitch_model, ckpt=ckpt, n_speakers=n_speakers, device=fastpitch_model.device)

            if self.path == "/synthesize":
                text = post_data["sequence"]
                pace = float(post_data["pace"])
                out_path = post_data["outfile"]
                pitch = post_data["pitch"] if "pitch" in post_data else None
                duration = post_data["duration"] if "duration" in post_data else None
                speaker_i = post_data["speaker_i"] if "speaker_i" in post_data else None
                vocoder = post_data["vocoder"]
                pitch_data = [pitch, duration]
                old_sequence = post_data["old_sequence"] if "old_sequence" in post_data else None

                req_response = fastpitch.infer(PROD, user_settings, text, out_path, fastpitch=fastpitch_model, vocoder=vocoder, \
                    speaker_i=speaker_i, pitch_data=pitch_data, logger=logger, pace=pace, old_sequence=old_sequence)

            if self.path == "/synthesize_batch":
                linesBatch = post_data["linesBatch"]
                speaker_i = post_data["speaker_i"]
                vocoder = post_data["vocoder"]
                try:
                    req_response = fastpitch.infer_batch(PROD, user_settings, linesBatch, fastpitch=fastpitch_model, vocoder=vocoder, \
                        speaker_i=speaker_i, logger=logger)
                except RuntimeError as e:
                    if "CUDA out of memory" in str(e):
                        req_response = "CUDA OOM"
                    else:
                        req_response = str(e)


            if self.path == "/outputAudio":
                input_path = post_data["input_path"]
                output_path = post_data["output_path"]
                options = json.loads(post_data["options"])
                req_response = run_audio_post(logger, input_path, output_path, options)

            self._set_response()
            self.wfile.write(req_response.encode("utf-8"))
        except Exception as e:
            with open("./DEBUG_request.txt", "w+") as f:
                f.write(traceback.format_exc())
                f.write(str(post_data))
            logger.info("Post Error:\n {}".format(repr(e)))
            print(traceback.format_exc())
            logger.info(traceback.format_exc())
コード例 #3
0
    def do_POST(self):
        post_data = ""
        try:
            global fastpitch_model
            logger.info("POST {}".format(self.path))

            content_length = int(self.headers['Content-Length'])
            post_data = json.loads(self.rfile.read(content_length).decode('utf-8'))
            req_response = "POST request for {}".format(self.path)

            print("POST")
            print(self.path)


            if self.path == "/setVocoder":
                logger.info(post_data)
                vocoder = post_data["vocoder"]
                user_settings["vocoder"] = vocoder
                hifi_gan = "waveglow" not in vocoder
                write_settings()

                if vocoder not in ["qnd", "256_waveglow", "big_waveglow"]:
                    use_gpu = user_settings["use_gpu"]
                    fastpitch_model = fastpitch.init_hifigan(PROD, fastpitch_model, use_gpu, vocoder)

                if not hifi_gan:
                    use_gpu = user_settings["use_gpu"]
                    fastpitch_model = fastpitch.init_waveglow(use_gpu, fastpitch_model, vocoder, logger)

            if self.path == "/customEvent":
                plugin_manager.run_plugins(plist=plugin_manager.plugins["custom-event"], event="custom-event", data=post_data)

            if self.path == "/setDevice":
                logger.info(post_data)
                use_gpu = post_data["device"]=="gpu"
                setDevice(use_gpu)

                user_settings["use_gpu"] = use_gpu
                write_settings()

            if self.path == "/loadModel":
                logger.info(post_data)
                ckpt = post_data["model"]
                n_speakers = post_data["model_speakers"] if "model_speakers" in post_data else None
                plugin_manager.run_plugins(plist=plugin_manager.plugins["load-model"]["pre"], event="pre load-model", data=ckpt)
                fastpitch_model = fastpitch.loadModel(fastpitch_model, ckpt=ckpt, n_speakers=n_speakers, device=fastpitch_model.device)
                plugin_manager.run_plugins(plist=plugin_manager.plugins["load-model"]["post"], event="post load-model", data=ckpt)

            if self.path == "/synthesize":
                text = post_data["sequence"]
                pace = float(post_data["pace"])
                out_path = post_data["outfile"]
                pitch = post_data["pitch"] if "pitch" in post_data else None
                duration = post_data["duration"] if "duration" in post_data else None
                speaker_i = post_data["speaker_i"] if "speaker_i" in post_data else None
                vocoder = post_data["vocoder"]
                pitch_data = [pitch, duration]
                old_sequence = post_data["old_sequence"] if "old_sequence" in post_data else None

                plugin_manager.run_plugins(plist=plugin_manager.plugins["synth-line"]["pre"], event="pre synth-line", data=post_data)
                req_response = fastpitch.infer(PROD, user_settings, text, out_path, fastpitch=fastpitch_model, vocoder=vocoder, \
                    speaker_i=speaker_i, pitch_data=pitch_data, logger=logger, pace=pace, old_sequence=old_sequence)
                plugin_manager.run_plugins(plist=plugin_manager.plugins["synth-line"]["post"], event="post synth-line", data=post_data)

            if self.path == "/synthesize_batch":
                linesBatch = post_data["linesBatch"]
                speaker_i = post_data["speaker_i"]
                vocoder = post_data["vocoder"]
                try:
                    req_response = fastpitch.infer_batch(PROD, user_settings, linesBatch, fastpitch=fastpitch_model, vocoder=vocoder, \
                        speaker_i=speaker_i, logger=logger)
                except RuntimeError as e:
                    if "CUDA out of memory" in str(e):
                        req_response = "CUDA OOM"
                    else:
                        req_response = str(e)


            if self.path == "/outputAudio":
                input_path = post_data["input_path"]
                output_path = post_data["output_path"]
                options = json.loads(post_data["options"])
                # For plugins
                extraInfo = {}
                if "extraInfo" in post_data:
                    extraInfo = json.loads(post_data["extraInfo"])
                    extraInfo["audio_options"] = options
                    extraInfo["input_path"] = input_path
                    extraInfo["output_path"] = output_path
                    extraInfo["ffmpeg"] = ffmpeg

                plugin_manager.run_plugins(plist=plugin_manager.plugins["output-audio"]["pre"], event="pre output-audio", data=extraInfo)
                req_response = run_audio_post(logger, input_path, output_path, options)
                plugin_manager.run_plugins(plist=plugin_manager.plugins["output-audio"]["post"], event="post output-audio", data=extraInfo)

            if self.path == "/refreshPlugins":
                status = plugin_manager.refresh_active_plugins()
                logger.info("status")
                logger.info(status)
                req_response = ",".join(status)


            self._set_response()
            self.wfile.write(req_response.encode("utf-8"))
        except Exception as e:
            with open("./DEBUG_request.txt", "w+") as f:
                f.write(traceback.format_exc())
                f.write(str(post_data))
            logger.info("Post Error:\n {}".format(repr(e)))
            print(traceback.format_exc())
            logger.info(traceback.format_exc())