diff --git a/speechserving/setup.py b/speechserving/setup.py new file mode 100644 index 000000000..e69de29bb diff --git a/speechserving/speechserving/__init__.py b/speechserving/speechserving/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/speechserving/speechserving/bin/main.py b/speechserving/speechserving/bin/main.py new file mode 100644 index 000000000..ffc2228f3 --- /dev/null +++ b/speechserving/speechserving/bin/main.py @@ -0,0 +1,39 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import argparse + + + +def init(args): + """ 系统初始化 + """ + + +def main(args): + """主程序入口""" + + if init(args): + app.run(host='0.0.0.0', port=conf.port) + + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--config_file", action="store", + help="yaml file of the app", default="./conf/application.yaml") + parser.add_argument("--log_file", action="store", + help="log file", default="./log/paddlespeech.log") + args = parser.parse_args() + + main(args) diff --git a/speechserving/speechserving/bin/paddlespeech-client.py b/speechserving/speechserving/bin/paddlespeech-client.py new file mode 100644 index 000000000..ffc2228f3 --- /dev/null +++ b/speechserving/speechserving/bin/paddlespeech-client.py @@ -0,0 +1,39 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import argparse + + + +def init(args): + """ 系统初始化 + """ + + +def main(args): + """主程序入口""" + + if init(args): + app.run(host='0.0.0.0', port=conf.port) + + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--config_file", action="store", + help="yaml file of the app", default="./conf/application.yaml") + parser.add_argument("--log_file", action="store", + help="log file", default="./log/paddlespeech.log") + args = parser.parse_args() + + main(args) diff --git a/speechserving/speechserving/bin/paddlespeech-server.py b/speechserving/speechserving/bin/paddlespeech-server.py new file mode 100644 index 000000000..ffc2228f3 --- /dev/null +++ b/speechserving/speechserving/bin/paddlespeech-server.py @@ -0,0 +1,39 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import argparse + + + +def init(args): + """ 系统初始化 + """ + + +def main(args): + """主程序入口""" + + if init(args): + app.run(host='0.0.0.0', port=conf.port) + + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--config_file", action="store", + help="yaml file of the app", default="./conf/application.yaml") + parser.add_argument("--log_file", action="store", + help="log file", default="./log/paddlespeech.log") + args = parser.parse_args() + + main(args) diff --git a/speechserving/speechserving/conf/application.yaml b/speechserving/speechserving/conf/application.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/speechserving/speechserving/conf/asr/asr.yaml b/speechserving/speechserving/conf/asr/asr.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/speechserving/speechserving/controller/api.py b/speechserving/speechserving/controller/api.py new file mode 100644 index 000000000..188dba30d --- /dev/null +++ b/speechserving/speechserving/controller/api.py @@ -0,0 +1,50 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from fastapi import APIRouter + +router = APIRouter() + + +router.include_router(auth_router) +router.include_router(user_router) +router.include_router(profile_router) +router.include_router(comment_router) +router.include_router(article_router) +router.include_router(tag_router) + + + + +def init_app(app): + + asr,tts + + + + + + if asr + backend + dyload(asr) + + asr.register_router(router) + if tts + backend + dyload(asr) + + + asr.register_router(router) + + app.include_router(router) + diff --git a/speechserving/speechserving/engine/__init__.py b/speechserving/speechserving/engine/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/speechserving/speechserving/engine/asr/python/asr_engine.py b/speechserving/speechserving/engine/asr/python/asr_engine.py new file mode 100644 index 000000000..1ea3cd2a6 --- /dev/null +++ b/speechserving/speechserving/engine/asr/python/asr_engine.py @@ -0,0 +1,42 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from engine import BaseEngine + +__all__ = ['ASREngine'] + +class ASREngine(BaseEngine): + + def __init__(self, name): + super(ASREngine, self).__init__() + + + def init(self): + pass + + def postprocess(self): + pass + + def run(self): + pass + + + +if __name__ == "__main__": + # test Singleton + class1 = ASREngine("ASREngine") + class2 = ASREngine() + print(class1 is class2) + print(id(class1)) + print(id(class2)) + diff --git a/speechserving/speechserving/engine/base_engine.py b/speechserving/speechserving/engine/base_engine.py new file mode 100644 index 000000000..1f9f6fa0b --- /dev/null +++ b/speechserving/speechserving/engine/base_engine.py @@ -0,0 +1,57 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +from typing import Any +from typing import List +from typing import Union + +from pattern_singleton import Singleton + +class BaseEngine(metaclass=Singleton): + """ + An base engine class + """ + + def __init__(self): + self._inputs = dict() + self._outputs = dict() + + def init(self, *args, **kwargs): + """ + init the engine + + Returns: + bool: true or false + """ + pass + + def postprocess(self, *args, **kwargs) -> Union[str, os.PathLike]: + """ + Output postprocess and return results. + This method get model output from self._outputs and convert it into human-readable results. + + Returns: + Union[str, os.PathLike]: Human-readable results such as texts and audio files. + """ + pass + + def run(self, *args, **kwargs) -> Union[str, os.PathLike]: + """ + Output postprocess and return results. + This method get model output from self._outputs and convert it into human-readable results. + + Returns: + Union[str, os.PathLike]: Human-readable results such as texts and audio files. + """ + pass diff --git a/speechserving/speechserving/main.py b/speechserving/speechserving/main.py new file mode 100644 index 000000000..91046984a --- /dev/null +++ b/speechserving/speechserving/main.py @@ -0,0 +1,43 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import argparse + +import asr_api as api_run +import tts_api as api_run + + + +def init(args): + """ 系统初始化 + """ + + +def main(args): + """主程序入口""" + + if init(args): + api_run.run() + app.run(host='0.0.0.0', port=conf.port) + + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--config_file", action="store", + help="yaml file of the app", default="./conf/application.yaml") + parser.add_argument("--log_file", action="store", + help="log file", default="./log/paddlespeech.log") + args = parser.parse_args() + + main(args) diff --git a/speechserving/speechserving/restful/__init__.py b/speechserving/speechserving/restful/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/speechserving/speechserving/restful/api.py b/speechserving/speechserving/restful/api.py new file mode 100644 index 000000000..6324fac23 --- /dev/null +++ b/speechserving/speechserving/restful/api.py @@ -0,0 +1,31 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from fastapi import APIRouter + +router = APIRouter() + + +router.include_router(auth_router) +router.include_router(user_router) +router.include_router(profile_router) +router.include_router(comment_router) +router.include_router(article_router) +router.include_router(tag_router) + + + + +def init_app(app): + + app.include_router(router) diff --git a/speechserving/speechserving/restful/request.py b/speechserving/speechserving/restful/request.py new file mode 100644 index 000000000..4721decde --- /dev/null +++ b/speechserving/speechserving/restful/request.py @@ -0,0 +1,56 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from typing import Optional +from typing import List + +from pydantic import BaseModel + + +__all__ = ['ASRRequest, TTSRequest'] + +#****************************************************************************************/ +#************************************ ASR request ***************************************/ +#****************************************************************************************/ +class ASRRequest(BaseModel): + """ + request body example + { + "audio": "exSI6ICJlbiIsCgkgICAgInBvc2l0aW9uIjogImZhbHNlIgoJf...", + "audio_format": "wav", + "sample_rate": 16000, + "lang ": "zh_cn", + "ptt ":false + } + """ + audio: str + audio_format: str + sample_rate: int + lang: str + ptt: Optional[bool] = None + + +#****************************************************************************************/ +#************************************ TTS request ***************************************/ +#****************************************************************************************/ +class TTSRequest(BaseModel): + """ + request body example + { + "audio": "exSI6ICJlbiIsCgkgICAgInBvc2l0aW9uIjogImZhbHNlIgoJf...", + "audio_format": "wav", + "sample_rate": 16000, + "lang ": "zh_cn", + "ptt ":false + } + """ \ No newline at end of file diff --git a/speechserving/speechserving/restful/response.py b/speechserving/speechserving/restful/response.py new file mode 100644 index 000000000..fdb07a84a --- /dev/null +++ b/speechserving/speechserving/restful/response.py @@ -0,0 +1,52 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from typing import Optional +from typing import List + +from pydantic import BaseModel + +__all__ = ['ASRResponse'] + + +class Message(BaseModel): + description: str + +#****************************************************************************************/ +#************************************ ASR response **************************************/ +#****************************************************************************************/ +class AsrResult(BaseModel): + transcription: str + +class ASRResponse(BaseModel): + """ + response example + { + "success": true, + "code": 0, + "message": { + "description": "success" + } + "result": { + "transcription": "你好,飞桨" + } + } + """ + success: bool + code: int + message: Message + result: AsrResult + +#****************************************************************************************/ +#************************************ TTS response **************************************/ +#****************************************************************************************/