mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-07-12 21:03:59 +00:00
f4cc595e50
Introduce internal/audio package with Manager orchestrating TTS, STT, Music, and SFX providers via 4 interfaces. Phase 1 wires TTS providers (ElevenLabs, OpenAI, Edge, MiniMax) and ElevenLabs SFX; STT/Music wiring deferred to later phases. ElevenLabs TTS and SFX share an xi-api-key HTTP client.
27 lines
1.2 KiB
Go
27 lines
1.2 KiB
Go
package audio
|
|
|
|
import "regexp"
|
|
|
|
// stripMarkdown removes common markdown formatting so TTS reads prose, not
|
|
// syntax characters. Preserves inner text of bold/italic/inline code/links.
|
|
func stripMarkdown(text string) string {
|
|
text = regexp.MustCompile("(?s)```[^`]*```").ReplaceAllString(text, "")
|
|
text = regexp.MustCompile("`([^`]+)`").ReplaceAllString(text, "$1")
|
|
text = regexp.MustCompile(`\*\*([^*]+)\*\*`).ReplaceAllString(text, "$1")
|
|
text = regexp.MustCompile(`\*([^*]+)\*`).ReplaceAllString(text, "$1")
|
|
text = regexp.MustCompile(`__([^_]+)__`).ReplaceAllString(text, "$1")
|
|
text = regexp.MustCompile(`_([^_]+)_`).ReplaceAllString(text, "$1")
|
|
text = regexp.MustCompile(`\[([^\]]+)\]\([^)]+\)`).ReplaceAllString(text, "$1")
|
|
text = regexp.MustCompile(`(?m)^#+\s+`).ReplaceAllString(text, "")
|
|
return text
|
|
}
|
|
|
|
// stripTtsDirectives removes [[tts...]] markup from text.
|
|
// `[[tts:text]]...[[/tts:text]]` blocks keep their inner content.
|
|
// Bare `[[tts]]` and `[[tts:something]]` tags are removed entirely.
|
|
func stripTtsDirectives(text string) string {
|
|
text = regexp.MustCompile(`(?s)\[\[tts:text\]\](.*?)\[\[/tts:text\]\]`).ReplaceAllString(text, "$1")
|
|
text = regexp.MustCompile(`\[\[tts(?::[^\]]*)?\]\]`).ReplaceAllString(text, "")
|
|
return text
|
|
}
|