liumaolin
commited on
Commit
·
8587958
1
Parent(s):
941bf07
Clean input text in MoYoYo TTS by removing punctuation for better processing
Browse files
src/voice_dialogue/services/audio/generators/runtime/moyoyo.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import sys
|
| 2 |
import typing
|
| 3 |
from typing import Tuple
|
|
@@ -56,5 +57,12 @@ class MoYoYoTTS(TTSInterface):
|
|
| 56 |
if not self.is_ready:
|
| 57 |
raise RuntimeError("TTS module is not ready. Please call setup() first.")
|
| 58 |
|
|
|
|
|
|
|
| 59 |
(sample_rate, audio_data), *_ = self.tts_module.generate_audio(text)
|
| 60 |
return audio_data, sample_rate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
import sys
|
| 3 |
import typing
|
| 4 |
from typing import Tuple
|
|
|
|
| 57 |
if not self.is_ready:
|
| 58 |
raise RuntimeError("TTS module is not ready. Please call setup() first.")
|
| 59 |
|
| 60 |
+
text = self._clean_text(text)
|
| 61 |
+
|
| 62 |
(sample_rate, audio_data), *_ = self.tts_module.generate_audio(text)
|
| 63 |
return audio_data, sample_rate
|
| 64 |
+
|
| 65 |
+
def _clean_text(self, text: str) -> str:
|
| 66 |
+
"""去除文本中的中英文标点符号。"""
|
| 67 |
+
# 去除中英文标点符号,保留字母、数字、下划线、中文和空格
|
| 68 |
+
return re.sub(r'[^\w\s\u4e00-\u9fa5]', ' ', text)
|