From 147018a8b478f3a358dd2b0e388f0a581d671718 Mon Sep 17 00:00:00 2001 From: WilliamZhang06 Date: Wed, 23 Feb 2022 17:10:27 +0800 Subject: [PATCH] added cli changed code, test=doc --- paddlespeech/cli/asr/infer.py | 19 +++++++++---------- .../server/bin/paddlespeech_server.py | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/paddlespeech/cli/asr/infer.py b/paddlespeech/cli/asr/infer.py index 72edd9d1..c2a096bf 100644 --- a/paddlespeech/cli/asr/infer.py +++ b/paddlespeech/cli/asr/infer.py @@ -287,7 +287,8 @@ class ASRExecutor(BaseExecutor): """ audio_file = input - logger.info("Preprocess audio_file:" + audio_file) + if isinstance(audio_file, (str, os.PathLike)): + logger.info("Preprocess audio_file:" + audio_file) # Get the object for feature extraction if "deepspeech2online" in model_type or "deepspeech2offline" in model_type: @@ -408,13 +409,8 @@ class ASRExecutor(BaseExecutor): def _check(self, audio_file: str, sample_rate: int, force_yes: bool): self.sample_rate = sample_rate if self.sample_rate != 16000 and self.sample_rate != 8000: - logger.error("please input --sr 8000 or --sr 16000") - raise Exception("invalid sample rate") - sys.exit(-1) - - if not os.path.isfile(audio_file): - logger.error("Please input the right audio file path") - sys.exit(-1) + logger.error("invalid sample rate, please input --sr 8000 or --sr 16000") + return False logger.info("checking the audio file format......") try: @@ -431,7 +427,7 @@ class ASRExecutor(BaseExecutor): sample rate: 8k \n \ sox input_audio.xx --rate 8k --bits 16 --channels 1 output_audio.wav \n \ ") - sys.exit(-1) + return False logger.info("The sample rate is %d" % audio_sample_rate) if audio_sample_rate != self.sample_rate: logger.warning("The sample rate of the input file is not {}.\n \ @@ -465,6 +461,8 @@ class ASRExecutor(BaseExecutor): logger.info("The audio file format is right") self.change_format = False + return True + def execute(self, argv: List[str]) -> bool: """ Command line entry. @@ -517,7 +515,8 @@ class ASRExecutor(BaseExecutor): Python API to call an executor. """ audio_file = os.path.abspath(audio_file) - self._check(audio_file, sample_rate, force_yes) + if not self._check(audio_file, sample_rate, force_yes): + sys.exit(-1) paddle.set_device(device) self._init_from_path(model, lang, sample_rate, config, decode_method, ckpt_path) diff --git a/paddlespeech/server/bin/paddlespeech_server.py b/paddlespeech/server/bin/paddlespeech_server.py index 8651eb43..5b70e227 100644 --- a/paddlespeech/server/bin/paddlespeech_server.py +++ b/paddlespeech/server/bin/paddlespeech_server.py @@ -74,4 +74,4 @@ class ServerExecutor(BaseExecutor): config = get_config(args.config_file) if self.init(config): - uvicorn.run(app, host=config.host, port=config.port, debug=True)v \ No newline at end of file + uvicorn.run(app, host=config.host, port=config.port, debug=True) \ No newline at end of file