You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PaddleSpeech/paddlespeech/server/restful/response.py

108 lines
2.9 KiB

3 years ago
# 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 List
from typing import Optional
3 years ago
from pydantic import BaseModel
__all__ = ['ASRResponse', 'TTSResponse']
3 years ago
class Message(BaseModel):
description: str
3 years ago
#****************************************************************************************/
#************************************ ASR response **************************************/
#****************************************************************************************/
class AsrResult(BaseModel):
transcription: str
3 years ago
class ASRResponse(BaseModel):
"""
response example
{
"success": true,
"code": 0,
"message": {
"description": "success"
},
3 years ago
"result": {
"transcription": "你好,飞桨"
}
}
"""
success: bool
code: int
message: Message
result: AsrResult
3 years ago
#****************************************************************************************/
#************************************ TTS response **************************************/
#****************************************************************************************/
class TTSResult(BaseModel):
lang: str = "zh"
sample_rate: int
spk_id: int = 0
speed: float = 1.0
volume: float = 1.0
save_path: str = None
audio: str
class TTSResponse(BaseModel):
"""
response example
{
"success": true,
"code": 200,
"message": {
"description": "success"
},
"result": {
"lang": "zh",
"sample_rate": 24000,
"speed": 1.0,
"volume": 1.0,
"audio": "LTI1OTIuNjI1OTUwMzQsOTk2OS41NDk4...",
"save_path": "./tts.wav"
}
}
"""
success: bool
code: int
message: Message
result: TTSResult
#****************************************************************************************/
#********************************** Error response **************************************/
#****************************************************************************************/
class ErrorResponse(BaseModel):
"""
response example
{
"success": false,
"code": 0,
"message": {
"description": "Unknown error occurred."
}
}
"""
success: bool
code: int
message: Message