Clean and fix docs
This commit is contained in:
@@ -1,81 +0,0 @@
|
||||
import re
|
||||
|
||||
|
||||
def extract_language_and_text_updated(speaker, dialogue):
|
||||
# 使用正则表达式匹配<语言>标签和其后的文本
|
||||
pattern_language_text = r"<(\S+?)>([^<]+)"
|
||||
matches = re.findall(pattern_language_text, dialogue, re.DOTALL)
|
||||
speaker = speaker[1:-1]
|
||||
# 清理文本:去除两边的空白字符
|
||||
matches_cleaned = [(lang.upper(), text.strip()) for lang, text in matches]
|
||||
matches_cleaned.append(speaker)
|
||||
return matches_cleaned
|
||||
|
||||
|
||||
def validate_text(input_text):
|
||||
# 验证说话人的正则表达式
|
||||
pattern_speaker = r"(\[\S+?\])((?:\s*<\S+?>[^<\[\]]+?)+)"
|
||||
|
||||
# 使用re.DOTALL标志使.匹配包括换行符在内的所有字符
|
||||
matches = re.findall(pattern_speaker, input_text, re.DOTALL)
|
||||
|
||||
# 对每个匹配到的说话人内容进行进一步验证
|
||||
for _, dialogue in matches:
|
||||
language_text_matches = extract_language_and_text_updated(_, dialogue)
|
||||
if not language_text_matches:
|
||||
return (
|
||||
False,
|
||||
"Error: Invalid format detected in dialogue content. Please check your input.",
|
||||
)
|
||||
|
||||
# 如果输入的文本中没有找到任何匹配项
|
||||
if not matches:
|
||||
return (
|
||||
False,
|
||||
"Error: No valid speaker format detected. Please check your input.",
|
||||
)
|
||||
|
||||
return True, "Input is valid."
|
||||
|
||||
|
||||
def text_matching(text: str) -> list:
|
||||
speaker_pattern = r"(\[\S+?\])(.+?)(?=\[\S+?\]|$)"
|
||||
matches = re.findall(speaker_pattern, text, re.DOTALL)
|
||||
result = []
|
||||
for speaker, dialogue in matches:
|
||||
result.append(extract_language_and_text_updated(speaker, dialogue))
|
||||
return result
|
||||
|
||||
|
||||
def cut_para(text):
|
||||
splitted_para = re.split("[\n]", text) # 按段分
|
||||
splitted_para = [
|
||||
sentence.strip() for sentence in splitted_para if sentence.strip()
|
||||
] # 删除空字符串
|
||||
return splitted_para
|
||||
|
||||
|
||||
def cut_sent(para):
|
||||
para = re.sub("([。!;?\?])([^”’])", r"\1\n\2", para) # 单字符断句符
|
||||
para = re.sub("(\.{6})([^”’])", r"\1\n\2", para) # 英文省略号
|
||||
para = re.sub("(\…{2})([^”’])", r"\1\n\2", para) # 中文省略号
|
||||
para = re.sub("([。!?\?][”’])([^,。!?\?])", r"\1\n\2", para)
|
||||
para = para.rstrip() # 段尾如果有多余的\n就去掉它
|
||||
return para.split("\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
text = """
|
||||
[说话人1]
|
||||
[说话人2]<zh>你好吗?<jp>元気ですか?<jp>こんにちは,世界。<zh>你好吗?
|
||||
[说话人3]<zh>谢谢。<jp>どういたしまして。
|
||||
"""
|
||||
text_matching(text)
|
||||
# 测试函数
|
||||
test_text = """
|
||||
[说话人1]<zh>你好,こんにちは!<jp>こんにちは,世界。
|
||||
[说话人2]<zh>你好吗?
|
||||
"""
|
||||
text_matching(test_text)
|
||||
res = validate_text(test_text)
|
||||
print(res)
|
||||
@@ -215,13 +215,13 @@ def get_logger(
|
||||
|
||||
def get_steps(model_path: Union[str, Path]) -> Optional[int]:
|
||||
"""
|
||||
モデルのパスからイテレーション番号を取得する
|
||||
モデルのパスからイテレーション回数を取得する
|
||||
|
||||
Args:
|
||||
model_path (Union[str, Path]): モデルのパス
|
||||
|
||||
Returns:
|
||||
Optional[int]: イテレーション番号
|
||||
Optional[int]: イテレーション回数
|
||||
"""
|
||||
|
||||
matches = re.findall(r"\d+", model_path) # type: ignore
|
||||
|
||||
@@ -27,7 +27,7 @@ def load_checkpoint(
|
||||
for_infer (bool): 推論用に読み込むかどうかのフラグ
|
||||
|
||||
Returns:
|
||||
tuple[torch.nn.Module, Optional[torch.optim.Optimizer], float, int]: 更新されたモデルとオプティマイザー、学習率、イテレーション番号
|
||||
tuple[torch.nn.Module, Optional[torch.optim.Optimizer], float, int]: 更新されたモデルとオプティマイザー、学習率、イテレーション回数
|
||||
"""
|
||||
|
||||
assert os.path.isfile(checkpoint_path)
|
||||
@@ -104,7 +104,7 @@ def save_checkpoint(
|
||||
model (torch.nn.Module): 保存するモデル
|
||||
optimizer (Union[torch.optim.Optimizer, torch.optim.AdamW]): 保存するオプティマイザー
|
||||
learning_rate (float): 学習率
|
||||
iteration (int): イテレーション数
|
||||
iteration (int): イテレーション回数
|
||||
checkpoint_path (Union[str, Path]): 保存先のパス
|
||||
"""
|
||||
logger.info(
|
||||
|
||||
@@ -22,7 +22,7 @@ def load_safetensors(
|
||||
for_infer (bool): 推論用に読み込むかどうかのフラグ
|
||||
|
||||
Returns:
|
||||
tuple[torch.nn.Module, Optional[int]]: 読み込まれたモデルとイテレーション番号(存在する場合)
|
||||
tuple[torch.nn.Module, Optional[int]]: 読み込まれたモデルとイテレーション回数(存在する場合)
|
||||
"""
|
||||
|
||||
tensors: dict[str, Any] = {}
|
||||
@@ -64,7 +64,7 @@ def save_safetensors(
|
||||
|
||||
Args:
|
||||
model (torch.nn.Module): 保存するモデル
|
||||
iteration (int): イテレーション番号
|
||||
iteration (int): イテレーション回数
|
||||
checkpoint_path (Union[str, Path]): 保存先のパス
|
||||
is_half (bool): モデルを半精度で保存するかどうかのフラグ
|
||||
for_infer (bool): 推論用に保存するかどうかのフラグ
|
||||
|
||||
@@ -28,6 +28,7 @@ from style_bert_vits2.models.models import SynthesizerTrn
|
||||
from style_bert_vits2.models.models_jp_extra import (
|
||||
SynthesizerTrn as SynthesizerTrnJPExtra,
|
||||
)
|
||||
|
||||
from style_bert_vits2.logging import logger
|
||||
from style_bert_vits2.voice import adjust_voice
|
||||
|
||||
@@ -39,11 +40,7 @@ class TTSModel:
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
model_path: Path,
|
||||
config_path: Path,
|
||||
style_vec_path: Path,
|
||||
device: str,
|
||||
self, model_path: Path, config_path: Path, style_vec_path: Path, device: str
|
||||
) -> None:
|
||||
"""
|
||||
Style-Bert-Vits2 の音声合成モデルを初期化する。
|
||||
@@ -170,10 +167,10 @@ class TTSModel:
|
||||
language (Languages, optional): 言語. Defaults to Languages.JP.
|
||||
speaker_id (int, optional): 話者 ID. Defaults to 0.
|
||||
reference_audio_path (Optional[str], optional): 音声スタイルの参照元の音声ファイルのパス. Defaults to None.
|
||||
sdp_ratio (float, optional): SDP レシオ (値を大きくするとより感情豊かになる傾向がある). Defaults to DEFAULT_SDP_RATIO.
|
||||
noise (float, optional): ノイズの大きさ. Defaults to DEFAULT_NOISE.
|
||||
noise_w (float, optional): ノイズの大きさの重み. Defaults to DEFAULT_NOISEW.
|
||||
length (float, optional): 長さ. Defaults to DEFAULT_LENGTH.
|
||||
sdp_ratio (float, optional): DP と SDP の混合比。0 で DP のみ、1で SDP のみを使用 (値を大きくするとテンポに緩急がつく). Defaults to DEFAULT_SDP_RATIO.
|
||||
noise (float, optional): DP に与えられるノイズ. Defaults to DEFAULT_NOISE.
|
||||
noise_w (float, optional): SDP に与えられるノイズ. Defaults to DEFAULT_NOISEW.
|
||||
length (float, optional): 生成音声の長さ(話速)のパラメータ。大きいほど生成音声が長くゆっくり、小さいほど短く早くなる。 Defaults to DEFAULT_LENGTH.
|
||||
line_split (bool, optional): テキストを改行ごとに分割して生成するかどうか. Defaults to DEFAULT_LINE_SPLIT.
|
||||
split_interval (float, optional): 改行ごとに分割する場合の無音 (秒). Defaults to DEFAULT_SPLIT_INTERVAL.
|
||||
assist_text (Optional[str], optional): 感情表現の参照元の補助テキスト. Defaults to None.
|
||||
|
||||
@@ -19,7 +19,7 @@ def adjust_voice(
|
||||
fs (int): 音声のサンプリング周波数
|
||||
wave (NDArray[Any]): 音声データ
|
||||
pitch_scale (float, optional): ピッチの高さ. Defaults to 1.0.
|
||||
intonation_scale (float, optional): イントネーションの高さ. Defaults to 1.0.
|
||||
intonation_scale (float, optional): イントネーションの平均からの変更比率. Defaults to 1.0.
|
||||
|
||||
Returns:
|
||||
tuple[int, NDArray[Any]]: 調整後の音声データのサンプリング周波数と音声データ
|
||||
|
||||
Reference in New Issue
Block a user