Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

feat: 支持 TTS 播报#595

Merged
baiyao105 merged 57 commits into
Class-Widgets:mainfrom
baiyao105:feat_44
Jun 2, 2025
Merged

feat: 支持 TTS 播报#595
baiyao105 merged 57 commits into
Class-Widgets:mainfrom
baiyao105:feat_44

Conversation

@baiyao105

@baiyao105 baiyao105 commented May 1, 2025

Copy link
Copy Markdown
Member
compressed_final.mp4

文档说明 By Copilot

1. tip_toast.py

  • TTSAudioThread(QThread)

    • 每次弹窗需 TTS 时,启动一个独立线程负责调用 generate_speech_sync 生成语音并播放,防止主线程阻塞。
    • 通过全局 tts_is_playing 标志防止多线程重复播报,保证音频整洁。
    • TTS 线程支持中途安全退出,避免资源泄露。
    • 支持模板化文本生成,动态填充如课程名、时间等信息。
  • 主类tip_toast:

    • 启动弹窗时,判断 TTS 是否启用,是否有有效语音 ID 和播报文本,若满足条件则自动调用 TTS。
    • 支持中止上一个未完成的 TTS 线程,避免弹窗密集时的语音重叠。
    • 优化窗口关闭流程,确保音频/tts 线程能被安全终止。
    • 弹窗类型(上课/下课/预备/放学/通知)均支持单独配置 TTS 文本模板。
    • 日志细致区分各类异常和流程分支,便于追踪。

2. play_audio.py —— 音频播放底层逻辑

  • 支持通过 on_audio_played 回调自动清理临时 TTS 文件。
  • 对音频文件的有效性进行了更严格的判断(如文件大小、是否缓存),避免空文件或损坏文件导致死循环或卡死。
  • 日志输出全部使用相对路径,便于排查。
  • 优化了 pygame mixer 的初始化与异常兜底。
  • 支持缓存机制,仅对非缓存目录音频缓存,提升多次播放性能。
  • 统一了音量读取与设置逻辑,支持配置。

3. config/default_config.json

  • 新增 TTS 配置分区,包括:
    • enable:是否启用 TTS(0/1)
    • engine:TTS 引擎(如 edge/pyttsx3)
    • speed:语速
    • voice_id:可选,具体语音库
    • attend_class/finish_class/prepare_class/after_school/otherwise:各类弹窗的自定义播报模板,支持变量填充。

4. view/menu/sound.ui & tts_settings.ui

  • sound.ui:

    • 新增 TTS 语音设置按钮,为后续详细配置预留入口。
  • tts_settings.ui:

    • TTS 设置界面,自定义引擎、音色、测试

TTS 配置调整

  • 在 config/default_config.json 的 "TTS" 分区可手动调整参数:
    • "enable": 1 开启TTS,0为关闭
    • "engine": "edge" 指定TTS引擎(如 edge/pyttsx3,需环境支持)
    • "speed": 50 语速百分比
    • "voice_id": "" 可选,指定具体音色
    • "attend_class": "活动开始, {lesson_name}" 播报模板,变量支持见下表

支持的模板变量

变量名 说明
lesson_name 课程名称
minutes 提前分钟数
title 通知标题
content 通知正文

例如:"prepare_class": "活动即将开始, 下一节课 {lesson_name}, 提前 {minutes} 分钟"


@baiyao105 baiyao105 linked an issue May 1, 2025 that may be closed by this pull request
@baiyao105

This comment was marked as resolved.

@baiyao105

This comment was marked as resolved.

@IsHPDuwu

This comment was marked as outdated.

@IsHPDuwu IsHPDuwu marked this pull request as ready for review May 24, 2025 16:51
@IsHPDuwu IsHPDuwu requested review from a team, IsHPDuwu and pizeroLOL and removed request for a team May 24, 2025 16:51
@IsHPDuwu

This comment was marked as outdated.

baiyao105

This comment was marked as resolved.

@IsHPDuwu

This comment was marked as outdated.

Comment thread generate_speech.py Outdated
@IsHPDuwu IsHPDuwu self-requested a review June 1, 2025 05:10
@baiyao105 baiyao105 added test/failed/Linux 在Linux系统中未通过测试/存在问题 test/accepted/Windows 在Windows系统中已通过测试 and removed test/failed/Windows 在Windows系统中未通过测试/存在问题 test/accepted/Linux 在Linux系统中已通过测试 labels Jun 1, 2025
@IsHPDuwu IsHPDuwu requested a review from Artist-MOBAI June 1, 2025 06:52
IsHPDuwu

This comment was marked as outdated.

Comment thread menu.py Outdated
Comment thread menu.py
@IsHPDuwu IsHPDuwu requested a review from pizeroLOL June 1, 2025 10:10
@JerryQAQ-233

This comment was marked as resolved.

@IsHPDuwu IsHPDuwu added test/accepted/Linux 在Linux系统中已通过测试 and removed test/failed/Linux 在Linux系统中未通过测试/存在问题 labels Jun 1, 2025
IsHPDuwu

This comment was marked as off-topic.

@pizeroLOL pizeroLOL left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type hint 考虑补一下,其他问题不大。LGTM

@github-actions

github-actions Bot commented Jun 2, 2025

Copy link
Copy Markdown

🧪 PyLint 检查结果

🐍 Ruff 警告 ```txt $(cat ruff_output.txt | head -c 5000 || echo '无警告 🎉') ```
🚨 PyLint 致命错误 ```txt $(cat pylint_output.txt | grep -i 'fatal' || echo '无致命错误 🎉') ```

@baiyao105 baiyao105 merged commit 123b5a9 into Class-Widgets:main Jun 2, 2025
3 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

test/accepted/Linux 在Linux系统中已通过测试 test/accepted/Windows 在Windows系统中已通过测试 test/required/MacOS 需要在MacOS系统中进行测试

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Win7无法正常使用 [FEATURE]: TTS 语音播报

4 participants