feat: add more text formatting options

This commit is contained in:
莘权 马 2023-08-09 20:48:25 +08:00
parent f88fa9e2df
commit 63678de181
2 changed files with 58 additions and 14 deletions

View file

@ -4,18 +4,38 @@
@Time : 2023/7/1 22:50
@Author : alexanderwu
@File : test_azure_tts.py
@Modified By: mashenquan, 2023-8-9, add more text formatting options
"""
from metagpt.actions.azure_tts import AzureTTS
from metagpt.const import WORKSPACE_ROOT
def test_azure_tts():
azure_tts = AzureTTS("azure_tts")
azure_tts.synthesize_speech(
text = """
女儿看见父亲走了进来问道
<mstts:express-as role="YoungAdultFemale" style="calm">
您来的挺快的怎么过来的
</mstts:express-as>
父亲放下手提包
<mstts:express-as role="OlderAdultMale" style="calm">
Writing a binary file in Python is similar to writing a regular text file, but you'll work with bytes instead of strings.”
</mstts:express-as>
"""
path = WORKSPACE_ROOT / "tts"
path.mkdir(exist_ok=True, parents=True)
filename = path / "girl.wav"
result = azure_tts.synthesize_speech(
"zh-CN",
"zh-CN-YunxiNeural",
"Boy",
"你好,我是卡卡",
"output.wav")
"zh-CN-XiaomoNeural",
text=text,
output_file=str(filename))
print(result)
# 运行需要先配置 SUBSCRIPTION_KEY
# TODO: 这里如果要检验还要额外加上对应的asr才能确保前后生成是接近一致的但现在还没有
if __name__ == '__main__':
test_azure_tts()