提交 c94ebdc5 编写于 作者: K KP

Add python api for executor.

上级 e9798498
......@@ -14,6 +14,7 @@
import os
from abc import ABC
from abc import abstractmethod
from typing import List
from typing import Union
import paddle
......@@ -64,3 +65,17 @@ class BaseExecutor(ABC):
Output postprocess and return human-readable results such as texts and audio files.
"""
pass
@abstractmethod
def execute(self, argv: List[str]) -> bool:
"""
Command line entry.
"""
pass
@abstractmethod
def __call__(self, *arg, **kwargs):
"""
Python API to call an executor.
"""
pass
......@@ -126,6 +126,9 @@ class S2TExecutor(BaseExecutor):
pass
def execute(self, argv: List[str]) -> bool:
"""
Command line entry.
"""
parser_args = self.parser.parse_args(argv)
print(parser_args)
......@@ -137,12 +140,20 @@ class S2TExecutor(BaseExecutor):
device = parser_args.device
try:
self._init_from_path(model, lang, config, ckpt_path)
self.preprocess(audio_file)
self.infer()
res = self.postprocess() # Retrieve result of s2t.
res = self(model, lang, config, ckpt_path, audio_file, device)
print(res)
return True
except Exception as e:
print(e)
return False
def __call__(self, model, lang, config, ckpt_path, audio_file, device):
"""
Python API to call an executor.
"""
self._init_from_path(model, lang, config, ckpt_path)
self.preprocess(audio_file)
self.infer()
res = self.postprocess() # Retrieve result of s2t.
return res
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册