refactor: 完成 0.4.0 版本更新
完成 0.4.0 版本更新, 为了消除此前提交消息风格不一致与错误提交超大文件的问题, 维持代码统计数据的准确性和提交消息风格的一致性, 重新初始化仓库; 旧的提交历史在 HeurAMS-legacy 仓库(https://gitea.imwangzhiyu.xyz/ajax/HeurAMS-legacy)
This commit is contained in:
17
src/heurams/providers/tts/__init__.py
Normal file
17
src/heurams/providers/tts/__init__.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from .base import BaseTTS
|
||||
from .edge_tts import EdgeTTS
|
||||
from heurams.services.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
__all__ = [
|
||||
"BaseTTS",
|
||||
"EdgeTTS",
|
||||
]
|
||||
|
||||
providers = {
|
||||
"basetts": BaseTTS,
|
||||
"edgetts": EdgeTTS,
|
||||
}
|
||||
|
||||
logger.debug("TTS providers 已注册: %s", list(providers.keys()))
|
||||
15
src/heurams/providers/tts/base.py
Normal file
15
src/heurams/providers/tts/base.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pathlib
|
||||
from heurams.services.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
class BaseTTS:
|
||||
name = "BaseTTS"
|
||||
|
||||
@classmethod
|
||||
def convert(cls, text: str, path: pathlib.Path | str = "") -> pathlib.Path:
|
||||
"""path 是可选参数, 不填则自动返回生成文件路径"""
|
||||
logger.debug("BaseTTS.convert: text length=%d, path=%s", len(text), path)
|
||||
logger.warning("BaseTTS.convert 是基类方法, 未实现具体功能")
|
||||
return path # type: ignore
|
||||
26
src/heurams/providers/tts/edge_tts.py
Normal file
26
src/heurams/providers/tts/edge_tts.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from .base import BaseTTS
|
||||
import pathlib
|
||||
import edge_tts
|
||||
from heurams.services.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
class EdgeTTS(BaseTTS):
|
||||
name = "EdgeTTS"
|
||||
|
||||
@classmethod
|
||||
def convert(cls, text, path: pathlib.Path | str = "") -> pathlib.Path:
|
||||
logger.debug("EdgeTTS.convert: text length=%d, path=%s", len(text), path)
|
||||
try:
|
||||
communicate = edge_tts.Communicate(
|
||||
text,
|
||||
"zh-CN-YunjianNeural",
|
||||
)
|
||||
logger.debug("EdgeTTS 通信对象创建成功, 正在保存音频")
|
||||
communicate.save_sync(str(path))
|
||||
logger.debug("EdgeTTS 音频已保存到: %s", path)
|
||||
return path # type: ignore
|
||||
except Exception as e:
|
||||
logger.error("EdgeTTS.convert 失败: %s", e)
|
||||
raise
|
||||
Reference in New Issue
Block a user