Add python api for executor.

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

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

Loading…
Cancel
Save