提交 c94ebdc5 编写于 作者: K KP

Add python api for executor.

上级 e9798498
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
import os import os
from abc import ABC from abc import ABC
from abc import abstractmethod from abc import abstractmethod
from typing import List
from typing import Union from typing import Union
import paddle import paddle
...@@ -64,3 +65,17 @@ class BaseExecutor(ABC): ...@@ -64,3 +65,17 @@ class BaseExecutor(ABC):
Output postprocess and return human-readable results such as texts and audio files. Output postprocess and return human-readable results such as texts and audio files.
""" """
pass 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): ...@@ -126,6 +126,9 @@ class S2TExecutor(BaseExecutor):
pass pass
def execute(self, argv: List[str]) -> bool: def execute(self, argv: List[str]) -> bool:
"""
Command line entry.
"""
parser_args = self.parser.parse_args(argv) parser_args = self.parser.parse_args(argv)
print(parser_args) print(parser_args)
...@@ -137,12 +140,20 @@ class S2TExecutor(BaseExecutor): ...@@ -137,12 +140,20 @@ class S2TExecutor(BaseExecutor):
device = parser_args.device device = parser_args.device
try: try:
self._init_from_path(model, lang, config, ckpt_path) res = self(model, lang, config, ckpt_path, audio_file, device)
self.preprocess(audio_file)
self.infer()
res = self.postprocess() # Retrieve result of s2t.
print(res) print(res)
return True return True
except Exception as e: except Exception as e:
print(e) print(e)
return False 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.
先完成此消息的编辑!
想要评论请 注册