提交 eb7e964e 编写于 作者: L lym0302

add tts api, test=tts

上级 e66233fa
......@@ -11,8 +11,11 @@
# 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.tts.python.tts_engine import TTSEngine
from fastapi import APIRouter
from .request import TTSRequest
from .response import TTSResponse
router = APIRouter()
......@@ -24,6 +27,64 @@ def help():
Returns:
json: [description]
"""
return {'hello': 'world'}
json_body = {
"success": true,
"code": 0,
"message": {
"global": "success"
},
"result": {
"description": "tts server",
"text": "sentence to be synthesized",
"audio": "the base64 of audio"
}
}
return json_body
@router.post("/paddlespeech/tts", response_model=TTSResponse)
def tts(request_body: TTSRequest):
"""tts api
Args:
request_body (TTSRequest): [description]
Returns:
json: [description]
"""
# json to dict
item_dict = request_body.dict()
sentence = item_dict['text']
spk_id = item_dict['spk_id']
speed = item_dict['speed']
volume = item_dict['volume']
sample_rate = item_dict['sample_rate']
save_path = item_dict['save_path']
audio_format = item_dict['audio_format']
# single
tts_engine = TTSEngine()
#tts_engine.init()
lang, target_sample_rate, wav_base64 = tts_engine.run(
sentence, spk_id, speed, volume, sample_rate, save_path, audio_format)
#tts_engine.postprocess()
json_body = {
"success": True,
"code": 0,
"message": {
"description": "success"
},
"result": {
"lang": lang,
"spk_id": spk_id,
"speed": speed,
"volume": volume,
"sample_rate": target_sample_rate,
"save_path": save_path,
"audio": wav_base64
}
}
return json_body
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册