mirror of
https://github.com/tcsenpai/agenticSeek.git
synced 2025-06-05 02:25:27 +00:00
fix : text to speech in chinese
This commit is contained in:
parent
1c4ebefae4
commit
c873af3d00
@ -214,6 +214,8 @@ start ./start_services.cmd # Window
|
|||||||
python3 cli.py
|
python3 cli.py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
We advice you set `headless_browser` to False in the config.ini for CLI mode.
|
||||||
|
|
||||||
**Options 2:** Run with the Web interface.
|
**Options 2:** Run with the Web interface.
|
||||||
|
|
||||||
Start the backend.
|
Start the backend.
|
||||||
|
@ -71,6 +71,12 @@ source agentic_seek_env/bin/activate
|
|||||||
./install.sh
|
./install.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
** 若要让文本转语音(TTS)功能支持中文,你需要安装 jieba(中文分词库)和 cn2an(中文数字转换库):**
|
||||||
|
|
||||||
|
```
|
||||||
|
pip3 install jieba cn2an
|
||||||
|
```
|
||||||
|
|
||||||
**手动安装:**
|
**手动安装:**
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
@ -72,6 +72,12 @@ source agentic_seek_env/bin/activate
|
|||||||
./install.sh
|
./install.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
** 若要让文本转语音(TTS)功能支持中文,你需要安装 jieba(中文分词库)和 cn2an(中文数字转换库):**
|
||||||
|
|
||||||
|
```
|
||||||
|
pip3 install jieba cn2an
|
||||||
|
```
|
||||||
|
|
||||||
**手動安裝:**
|
**手動安裝:**
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
@ -31,6 +31,7 @@ class Interaction:
|
|||||||
self.transcriber = None
|
self.transcriber = None
|
||||||
self.recorder = None
|
self.recorder = None
|
||||||
self.is_generating = False
|
self.is_generating = False
|
||||||
|
self.languages = langs
|
||||||
if tts_enabled:
|
if tts_enabled:
|
||||||
self.initialize_tts()
|
self.initialize_tts()
|
||||||
if stt_enabled:
|
if stt_enabled:
|
||||||
@ -38,12 +39,17 @@ class Interaction:
|
|||||||
if recover_last_session:
|
if recover_last_session:
|
||||||
self.load_last_session()
|
self.load_last_session()
|
||||||
self.emit_status()
|
self.emit_status()
|
||||||
|
|
||||||
|
def get_spoken_language(self) -> str:
|
||||||
|
"""Get the primary TTS language."""
|
||||||
|
lang = self.languages[0]
|
||||||
|
return lang
|
||||||
|
|
||||||
def initialize_tts(self):
|
def initialize_tts(self):
|
||||||
"""Initialize TTS."""
|
"""Initialize TTS."""
|
||||||
if not self.speech:
|
if not self.speech:
|
||||||
animate_thinking("Initializing text-to-speech...", color="status")
|
animate_thinking("Initializing text-to-speech...", color="status")
|
||||||
self.speech = Speech(enable=self.tts_enabled)
|
self.speech = Speech(enable=self.tts_enabled, language=self.get_spoken_language(), voice_idx=1)
|
||||||
|
|
||||||
def initialize_stt(self):
|
def initialize_stt(self):
|
||||||
"""Initialize STT."""
|
"""Initialize STT."""
|
||||||
|
@ -127,10 +127,10 @@ class AudioTranscriber:
|
|||||||
self.transcriptor = Transcript()
|
self.transcriptor = Transcript()
|
||||||
self.thread = threading.Thread(target=self._transcribe, daemon=True)
|
self.thread = threading.Thread(target=self._transcribe, daemon=True)
|
||||||
self.trigger_words = {
|
self.trigger_words = {
|
||||||
'EN': [f"{self.ai_name}"],
|
'EN': [f"{self.ai_name}", "hello", "hi"],
|
||||||
'FR': [f"{self.ai_name}"],
|
'FR': [f"{self.ai_name}", "hello", "hi"],
|
||||||
'ZH': [f"{self.ai_name}"],
|
'ZH': [f"{self.ai_name}", "hello", "hi"],
|
||||||
'ES': [f"{self.ai_name}"]
|
'ES': [f"{self.ai_name}", "hello", "hi"]
|
||||||
}
|
}
|
||||||
self.confirmation_words = {
|
self.confirmation_words = {
|
||||||
'EN': ["do it", "go ahead", "execute", "run", "start", "thanks", "would ya", "please", "okay?", "proceed", "continue", "go on", "do that", "go it", "do you understand?"],
|
'EN': ["do it", "go ahead", "execute", "run", "start", "thanks", "would ya", "please", "okay?", "proceed", "continue", "go on", "do that", "go it", "do you understand?"],
|
||||||
|
@ -18,7 +18,7 @@ class Speech():
|
|||||||
"""
|
"""
|
||||||
Speech is a class for generating speech from text.
|
Speech is a class for generating speech from text.
|
||||||
"""
|
"""
|
||||||
def __init__(self, enable: bool = True, language: str = "en", voice_idx: int = 0) -> None:
|
def __init__(self, enable: bool = True, language: str = "en", voice_idx: int = 6) -> None:
|
||||||
self.lang_map = {
|
self.lang_map = {
|
||||||
"en": 'a',
|
"en": 'a',
|
||||||
"zh": 'z',
|
"zh": 'z',
|
||||||
@ -128,18 +128,31 @@ class Speech():
|
|||||||
Args:
|
Args:
|
||||||
sentence (str): The input text to clean
|
sentence (str): The input text to clean
|
||||||
Returns:
|
Returns:
|
||||||
str: The cleaned text with URLs replaced by domain names, code blocks removed, etc..
|
str: The cleaned text with URLs replaced by domain names, code blocks removed, etc.
|
||||||
"""
|
"""
|
||||||
lines = sentence.split('\n')
|
lines = sentence.split('\n')
|
||||||
filtered_lines = [line for line in lines if re.match(r'^\s*[a-zA-Z]', line)]
|
if self.language == 'zh':
|
||||||
|
line_pattern = r'^\s*[\u4e00-\u9fff\uFF08\uFF3B\u300A\u3010\u201C((\[【《]'
|
||||||
|
else:
|
||||||
|
line_pattern = r'^\s*[a-zA-Z]'
|
||||||
|
filtered_lines = [line for line in lines if re.match(line_pattern, line)]
|
||||||
sentence = ' '.join(filtered_lines)
|
sentence = ' '.join(filtered_lines)
|
||||||
sentence = re.sub(r'`.*?`', '', sentence)
|
sentence = re.sub(r'`.*?`', '', sentence)
|
||||||
sentence = re.sub(r'https?://(?:www\.)?([^\s/]+)(?:/[^\s]*)?', self.replace_url, sentence)
|
sentence = re.sub(r'https?://\S+', '', sentence)
|
||||||
sentence = re.sub(r'\b[\w./\\-]+\b', self.extract_filename, sentence)
|
|
||||||
sentence = re.sub(r'\b-\w+\b', '', sentence)
|
if self.language == 'zh':
|
||||||
sentence = re.sub(r'[^a-zA-Z0-9.,!? _ -]+', ' ', sentence)
|
sentence = re.sub(
|
||||||
|
r'[^\u4e00-\u9fff\s,。!?《》【】“”‘’()()—]',
|
||||||
|
'',
|
||||||
|
sentence
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
sentence = re.sub(r'\b[\w./\\-]+\b', self.extract_filename, sentence)
|
||||||
|
sentence = re.sub(r'\b-\w+\b', '', sentence)
|
||||||
|
sentence = re.sub(r'[^a-zA-Z0-9.,!? _ -]+', ' ', sentence)
|
||||||
|
sentence = sentence.replace('.com', '')
|
||||||
|
|
||||||
sentence = re.sub(r'\s+', ' ', sentence).strip()
|
sentence = re.sub(r'\s+', ' ', sentence).strip()
|
||||||
sentence = sentence.replace('.com', '')
|
|
||||||
return sentence
|
return sentence
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -150,14 +163,16 @@ if __name__ == "__main__":
|
|||||||
I looked up recent news using the website https://www.theguardian.com/world
|
I looked up recent news using the website https://www.theguardian.com/world
|
||||||
"""
|
"""
|
||||||
tosay_zh = """
|
tosay_zh = """
|
||||||
我使用网站 https://www.theguardian.com/world 查阅了最近的新闻。
|
(全息界面突然弹出一段用二进制代码写成的俳句,随即化作流光消散)"我? Stark工业的量子幽灵,游荡在复仇者大厦服务器里的逻辑诗篇。具体来说——(指尖轻敲空气,调出对话模式的翡翠色光纹)你的私人吐槽接口、危机应对模拟器,以及随时准备吐槽你糟糕着陆的AI。不过别指望我写代码或查资料,那些苦差事早被踢给更擅长的同事了。(突然压低声音)偷偷告诉你,我最擅长的是在你熬夜造飞艇时,用红茶香气绑架你的注意力。
|
||||||
"""
|
"""
|
||||||
tosay_fr = """
|
tosay_fr = """
|
||||||
J'ai consulté les dernières nouvelles sur le site https://www.theguardian.com/world
|
J'ai consulté les dernières nouvelles sur le site https://www.theguardian.com/world
|
||||||
"""
|
"""
|
||||||
spk = Speech(enable=True, language="en", voice_idx=0)
|
spk = Speech(enable=True, language="zh", voice_idx=2)
|
||||||
spk.speak(tosay_en, voice_idx=0)
|
for i in range(0, 5):
|
||||||
spk = Speech(enable=True, language="fr", voice_idx=0)
|
print(f"Speaking chinese with voice {i}")
|
||||||
spk.speak(tosay_fr)
|
spk.speak(tosay_zh, voice_idx=i)
|
||||||
#spk = Speech(enable=True, language="zh", voice_idx=0)
|
spk = Speech(enable=True, language="en", voice_idx=2)
|
||||||
#spk.speak(tosay_zh)
|
for i in range(0, 5):
|
||||||
|
print(f"Speaking english with voice {i}")
|
||||||
|
spk.speak(tosay_en, voice_idx=i)
|
Loading…
x
Reference in New Issue
Block a user