Add python api for executor.

pull/1048/head
KP 3 years ago
parent e9798498d6
commit c94ebdc52c

@ -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

Loading…
Cancel
Save