From 31802947108cb12d708404fb621f287fd5d13716 Mon Sep 17 00:00:00 2001 From: XXXXRT666 <157766680+XXXXRT666@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:57:58 +0000 Subject: [PATCH 1/6] Update config.py Change the inference device for Mac to accelerate inference and reduce memory leak --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 3e9e951..caaadd4 100644 --- a/config.py +++ b/config.py @@ -20,7 +20,7 @@ python_exec = sys.executable or "python" if torch.cuda.is_available(): infer_device = "cuda" elif torch.backends.mps.is_available(): - infer_device = "mps" + infer_device = "cpu" else: infer_device = "cpu" From 861658050b6eab32ce6a34cfee37fc63a53a4ae7 Mon Sep 17 00:00:00 2001 From: XXXXRT666 <157766680+XXXXRT666@users.noreply.github.com> Date: Tue, 20 Feb 2024 16:03:08 +0000 Subject: [PATCH 2/6] Update inference_webui.py Change inference device to accelerate inference on Mac and reduce memory leak --- GPT_SoVITS/inference_webui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GPT_SoVITS/inference_webui.py b/GPT_SoVITS/inference_webui.py index c427b25..a046776 100644 --- a/GPT_SoVITS/inference_webui.py +++ b/GPT_SoVITS/inference_webui.py @@ -73,7 +73,7 @@ os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = '1' # 确保直接启动推理UI时 if torch.cuda.is_available(): device = "cuda" elif torch.backends.mps.is_available(): - device = "mps" + device = "cpu" else: device = "cpu" From 84062074a311d10da5998f10b5f3d36dc8467b5f Mon Sep 17 00:00:00 2001 From: KamioRinn Date: Wed, 21 Feb 2024 01:14:09 +0800 Subject: [PATCH 3/6] Adjust text normlization --- GPT_SoVITS/inference_webui.py | 5 +++-- GPT_SoVITS/text/chinese.py | 2 ++ GPT_SoVITS/text/zh_normalization/num.py | 15 +++++++++++++++ .../text/zh_normalization/text_normlization.py | 10 +++++++--- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/GPT_SoVITS/inference_webui.py b/GPT_SoVITS/inference_webui.py index c427b25..695121a 100644 --- a/GPT_SoVITS/inference_webui.py +++ b/GPT_SoVITS/inference_webui.py @@ -245,7 +245,7 @@ def get_phones_and_bert(text,language): formattext = " ".join(tmp["text"] for tmp in LangSegment.getTexts(text)) else: # 因无法区别中日文汉字,以用户输入为准 - formattext = re.sub('[a-zA-Z]', '', text) + formattext = text while " " in formattext: formattext = formattext.replace(" ", " ") phones, word2ph, norm_text = clean_text_inf(formattext, language) @@ -286,7 +286,7 @@ def get_phones_and_bert(text,language): bert_list.append(bert) bert = torch.cat(bert_list, dim=1) phones = sum(phones_list, []) - norm_text = ' '.join(norm_text_list) + norm_text = ''.join(norm_text_list) return phones,bert.to(dtype),norm_text @@ -375,6 +375,7 @@ def get_tts_wav(ref_wav_path, prompt_text, prompt_language, text, text_language, if (text[-1] not in splits): text += "。" if text_language != "en" else "." print(i18n("实际输入的目标文本(每句):"), text) phones2,bert2,norm_text2=get_phones_and_bert(text, text_language) + print(i18n("前端处理后的文本(每句):"), norm_text2) if not ref_free: bert = torch.cat([bert1, bert2], 1) all_phoneme_ids = torch.LongTensor(phones1+phones2).to(device).unsqueeze(0) diff --git a/GPT_SoVITS/text/chinese.py b/GPT_SoVITS/text/chinese.py index ea41db1..f9a4b36 100644 --- a/GPT_SoVITS/text/chinese.py +++ b/GPT_SoVITS/text/chinese.py @@ -34,6 +34,8 @@ rep_map = { "$": ".", "/": ",", "—": "-", + "~": "…", + "~":"…", } tone_modifier = ToneSandhi() diff --git a/GPT_SoVITS/text/zh_normalization/num.py b/GPT_SoVITS/text/zh_normalization/num.py index 8a54d3e..8ef7f48 100644 --- a/GPT_SoVITS/text/zh_normalization/num.py +++ b/GPT_SoVITS/text/zh_normalization/num.py @@ -172,6 +172,21 @@ def replace_range(match) -> str: return result +# ~至表达式 +RE_TO_RANGE = re.compile( + r'((-?)((\d+)(\.\d+)?)|(\.(\d+)))(%|°C|℃|度|摄氏度|cm2|cm²|cm3|cm³|cm|db|ds|kg|km|m2|m²|m³|m3|ml|m|mm|s)[~]((-?)((\d+)(\.\d+)?)|(\.(\d+)))(%|°C|℃|度|摄氏度|cm2|cm²|cm3|cm³|cm|db|ds|kg|km|m2|m²|m³|m3|ml|m|mm|s)') + +def replace_to_range(match) -> str: + """ + Args: + match (re.Match) + Returns: + str + """ + result = match.group(0).replace('~', '至') + return result + + def _get_value(value_string: str, use_zero: bool=True) -> List[str]: stripped = value_string.lstrip('0') if len(stripped) == 0: diff --git a/GPT_SoVITS/text/zh_normalization/text_normlization.py b/GPT_SoVITS/text/zh_normalization/text_normlization.py index 1250e96..712537d 100644 --- a/GPT_SoVITS/text/zh_normalization/text_normlization.py +++ b/GPT_SoVITS/text/zh_normalization/text_normlization.py @@ -33,6 +33,7 @@ from .num import RE_NUMBER from .num import RE_PERCENTAGE from .num import RE_POSITIVE_QUANTIFIERS from .num import RE_RANGE +from .num import RE_TO_RANGE from .num import replace_default_num from .num import replace_frac from .num import replace_negative_num @@ -40,6 +41,7 @@ from .num import replace_number from .num import replace_percentage from .num import replace_positive_quantifier from .num import replace_range +from .num import replace_to_range from .phonecode import RE_MOBILE_PHONE from .phonecode import RE_NATIONAL_UNIFORM_NUMBER from .phonecode import RE_TELEPHONE @@ -65,7 +67,7 @@ class TextNormalizer(): if lang == "zh": text = text.replace(" ", "") # 过滤掉特殊字符 - text = re.sub(r'[——《》【】<=>{}()()#&@“”^_|…\\]', '', text) + text = re.sub(r'[——《》【】<=>{}()()#&@“”^_|\\]', '', text) text = self.SENTENCE_SPLITOR.sub(r'\1\n', text) text = text.strip() sentences = [sentence.strip() for sentence in re.split(r'\n+', text)] @@ -73,8 +75,8 @@ class TextNormalizer(): def _post_replace(self, sentence: str) -> str: sentence = sentence.replace('/', '每') - sentence = sentence.replace('~', '至') - sentence = sentence.replace('~', '至') + # sentence = sentence.replace('~', '至') + # sentence = sentence.replace('~', '至') sentence = sentence.replace('①', '一') sentence = sentence.replace('②', '二') sentence = sentence.replace('③', '三') @@ -128,6 +130,8 @@ class TextNormalizer(): sentence = RE_TIME_RANGE.sub(replace_time, sentence) sentence = RE_TIME.sub(replace_time, sentence) + # 处理~波浪号作为至的替换 + sentence = RE_TO_RANGE.sub(replace_to_range, sentence) sentence = RE_TEMPERATURE.sub(replace_temperature, sentence) sentence = replace_measure(sentence) sentence = RE_FRAC.sub(replace_frac, sentence) From 220367f90c85f6dc20751c4a586320c463b28406 Mon Sep 17 00:00:00 2001 From: XXXXRT666 <157766680+XXXXRT666@users.noreply.github.com> Date: Wed, 21 Feb 2024 01:15:11 +0000 Subject: [PATCH 4/6] Update inference_webui.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 精简代码 --- GPT_SoVITS/inference_webui.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/GPT_SoVITS/inference_webui.py b/GPT_SoVITS/inference_webui.py index a046776..3a4bfb3 100644 --- a/GPT_SoVITS/inference_webui.py +++ b/GPT_SoVITS/inference_webui.py @@ -72,8 +72,6 @@ os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = '1' # 确保直接启动推理UI时 if torch.cuda.is_available(): device = "cuda" -elif torch.backends.mps.is_available(): - device = "cpu" else: device = "cpu" From db40317d9ceaf782b5ccb383e044281a0489f29a Mon Sep 17 00:00:00 2001 From: XXXXRT666 <157766680+XXXXRT666@users.noreply.github.com> Date: Wed, 21 Feb 2024 01:15:31 +0000 Subject: [PATCH 5/6] Update config.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 精简代码 --- config.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/config.py b/config.py index caaadd4..1f74128 100644 --- a/config.py +++ b/config.py @@ -19,8 +19,6 @@ exp_root = "logs" python_exec = sys.executable or "python" if torch.cuda.is_available(): infer_device = "cuda" -elif torch.backends.mps.is_available(): - infer_device = "cpu" else: infer_device = "cpu" From b0b039ad2154d9867ae77bd484367fc6a8d1d2c7 Mon Sep 17 00:00:00 2001 From: Kenn Zhang Date: Sat, 17 Feb 2024 09:57:18 +0000 Subject: [PATCH 6/6] =?UTF-8?q?Docker=E9=95=9C=E5=83=8F=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=AF=B9=E4=BA=8E=E9=95=9C=E5=83=8F=E7=9A=84?= =?UTF-8?q?Tag=E5=A2=9E=E5=8A=A0Git=20Commit=E7=9A=84Hash=E5=80=BC?= =?UTF-8?q?=EF=BC=8C=E4=BE=BF=E4=BA=8E=E7=9F=A5=E9=81=93=E9=95=9C=E5=83=8F?= =?UTF-8?q?=E4=B8=AD=E5=BA=94=E7=94=A8=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 4 +++- dockerbuild.sh | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index dc39f76..4eca27b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,4 +3,6 @@ logs output reference SoVITS_weights -.git \ No newline at end of file +GPT_weights +TEMP +.git diff --git a/dockerbuild.sh b/dockerbuild.sh index 1b3dcee..3a4a1e1 100755 --- a/dockerbuild.sh +++ b/dockerbuild.sh @@ -2,13 +2,20 @@ # 获取当前日期,格式为 YYYYMMDD DATE=$(date +%Y%m%d) +# 获取最新的 Git commit 哈希值的前 7 位 +COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-7) # 构建 full 版本的镜像 docker build --build-arg IMAGE_TYPE=full -t breakstring/gpt-sovits:latest . # 为同一个镜像添加带日期的标签 docker tag breakstring/gpt-sovits:latest breakstring/gpt-sovits:dev-$DATE +# 为同一个镜像添加带当前代码库Commit哈希值的标签 +docker tag breakstring/gpt-sovits:latest breakstring/gpt-sovits:dev-$COMMIT_HASH -# 构建 elite 版本的镜像 + +# 构建 elite 版本的镜像(无模型下载步骤,需手工将模型下载安装进容器) docker build --build-arg IMAGE_TYPE=elite -t breakstring/gpt-sovits:latest-elite . # 为同一个镜像添加带日期的标签 docker tag breakstring/gpt-sovits:latest-elite breakstring/gpt-sovits:dev-$DATE-elite +# 为同一个镜像添加带当前代码库Commit哈希值的标签 +docker tag breakstring/gpt-sovits:latest-elite breakstring/gpt-sovits:dev-$COMMIT_HASH-elite