7b62c2f8b4
## H5 底部导航修复 (Bug #10) - 精简 App.vue,移除重复 tabbar,仅保留全局样式 - uni-page 设置 height: calc(100% - 50px) + overflow-y: auto - 内容区域精确停在底部导航上方,独立滚动不再叠加 - 恢复 custom-tab-bar 组件 ## 项目进度文档 - PROGRESS.md 更新至 10 个 Bug 修复 - 新增 H5 底部导航修复记录 - 新增历史变更条目
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
from typing import Optional
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
try:
|
|
import edge_tts
|
|
HAS_EDGE_TTS = True
|
|
except ImportError:
|
|
HAS_EDGE_TTS = False
|
|
logger.warning("edge-tts not installed, TTS disabled")
|
|
|
|
VOICE_MAP = {
|
|
"zh": "zh-CN-XiaoxiaoNeural",
|
|
"en": "en-US-AriaNeural",
|
|
"ja": "ja-JP-NanamiNeural",
|
|
"ko": "ko-KR-SunHiNeural",
|
|
"fr": "fr-FR-DeniseNeural",
|
|
"de": "de-DE-KatjaNeural",
|
|
"es": "es-ES-ElviraNeural",
|
|
"pt": "pt-BR-FranciscaNeural",
|
|
"ru": "ru-RU-SvetlanaNeural",
|
|
"ar": "ar-SA-ZariyahNeural",
|
|
}
|
|
|
|
SUPPORTED_LANGS = list(VOICE_MAP.keys())
|
|
|
|
|
|
class TextToSpeechService:
|
|
@staticmethod
|
|
async def synthesize(text: str, lang: str = "en", rate: str = "0%", pitch: str = "0Hz") -> Optional[bytes]:
|
|
if not HAS_EDGE_TTS:
|
|
logger.warning("edge-tts not available")
|
|
return None
|
|
|
|
voice = VOICE_MAP.get(lang, VOICE_MAP["en"])
|
|
|
|
try:
|
|
communicate = edge_tts.Communicate(text, voice, rate=rate, pitch=pitch)
|
|
audio_data = b""
|
|
async for chunk in communicate.stream():
|
|
if chunk["type"] == "audio":
|
|
audio_data += chunk["data"]
|
|
return audio_data if audio_data else None
|
|
except Exception as e:
|
|
logger.error(f"TTS failed: {e}")
|
|
return None
|
|
|
|
|
|
tts_service = TextToSpeechService()
|