feat: Filter TTS rules based on language
Browse files- README.md +3 -0
- src/hooks/useAutoTTS.ts +15 -0
README.md
CHANGED
|
@@ -154,6 +154,9 @@ mitmproxy -p 8888
|
|
| 154 |
|
| 155 |
```bash
|
| 156 |
# /voice
|
|
|
|
|
|
|
|
|
|
| 157 |
# node-edge-tts
|
| 158 |
# local whisper-stt
|
| 159 |
uv venv
|
|
|
|
| 154 |
|
| 155 |
```bash
|
| 156 |
# /voice
|
| 157 |
+
"voiceTTSVoice": "zh-TW-HsiaoChenNeural",
|
| 158 |
+
"voiceLanguage": "zh-TW",
|
| 159 |
+
|
| 160 |
# node-edge-tts
|
| 161 |
# local whisper-stt
|
| 162 |
uv venv
|
src/hooks/useAutoTTS.ts
CHANGED
|
@@ -68,7 +68,22 @@ export function useAutoTTS(messages: RenderableMessage[], isLoading?: boolean):
|
|
| 68 |
: null
|
| 69 |
if (!textBlock?.text?.trim()) continue
|
| 70 |
|
|
|
|
| 71 |
const text = textBlock.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
const run = async () => {
|
| 74 |
const result = await edgeTts({ text, voice })
|
|
|
|
| 68 |
: null
|
| 69 |
if (!textBlock?.text?.trim()) continue
|
| 70 |
|
| 71 |
+
// Strip formatting before TTS: URLs, code blocks, markdown syntax
|
| 72 |
const text = textBlock.text
|
| 73 |
+
.replace(/https?:\/\/\S+/g, '') // URLs
|
| 74 |
+
.replace(/```[\s\S]*?```/g, '') // code blocks
|
| 75 |
+
.replace(/(?<=^|[^*])\*{1,2}(?!\*)(.*?)\*{1,2}(?=[^*]|$)/g, '$1') // *italic* **bold**
|
| 76 |
+
.replace(/(?<=^|[^_])\_{1,2}(?!_)(.*?)\_{1,2}(?=[^_]|$)/g, '$1') // _italic_ __bold__
|
| 77 |
+
.replace(/`([^`]+)`/g, '$1') // inline `code`
|
| 78 |
+
.replace(/~~(.*?)~~/g, '$1') // ~~strikethrough~~
|
| 79 |
+
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') // [text](url)
|
| 80 |
+
.replace(/^#{1,6}\s+/gm, '') // # headings
|
| 81 |
+
.replace(/^[>\|]\s*/gm, '') // > blockquotes, | tables
|
| 82 |
+
.replace(/(?:^|\n)[-*+]\s+/g, ' ') // list markers
|
| 83 |
+
.replace(/\n{3,}/g, '\n\n') // collapse excess newlines
|
| 84 |
+
.trim()
|
| 85 |
+
|
| 86 |
+
if (!text) continue
|
| 87 |
|
| 88 |
const run = async () => {
|
| 89 |
const result = await edgeTts({ text, voice })
|