parent
26524031d2
commit
2a530d49ff
@ -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)
|
@ -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)
|
@ -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)
|
@ -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)
|
||||||
|
|
@ -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))
|
||||||
|
|
@ -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
|
@ -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)
|
@ -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)
|
@ -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
|
||||||
|
}
|
||||||
|
"""
|
@ -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 **************************************/
|
||||||
|
#****************************************************************************************/
|
Loading…
Reference in new issue