fix(tts): 修复Android包可见性导致TTS未绑定问题,优化语音时序与引擎探测
This commit is contained in:
@@ -148,6 +148,19 @@ class _SessionScreenState extends State<SessionScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
void _speakStep(SessionStep step) {
|
||||
if (!_settings.enableVoicePrompt) return;
|
||||
if (step.type == StepType.inhale) {
|
||||
final medName = step.canister?.name.split(" ")[0] ?? '药物';
|
||||
TtsService().speak('请吸入$medName第${step.puffIndex}喷,口鼻密闭,慢而深地吸气。');
|
||||
} else if (step.type == StepType.intraPuffWait) {
|
||||
TtsService().speak('第${step.puffIndex}喷吸入完成,请等待三十秒后吸入下一喷。');
|
||||
} else if (step.type == StepType.crossDrugWait) {
|
||||
final minutes = step.durationSeconds ~/ 60;
|
||||
TtsService().speak('两药间隔开始,请等待$minutes分钟,待气道充分扩张。');
|
||||
}
|
||||
}
|
||||
|
||||
void _startStep(int index) {
|
||||
if (index >= _steps.length) {
|
||||
_finishSession();
|
||||
@@ -163,6 +176,8 @@ class _SessionScreenState extends State<SessionScreen> {
|
||||
_totalStageSeconds = step.durationSeconds;
|
||||
});
|
||||
|
||||
_speakStep(step);
|
||||
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
if (_remainingSeconds > 1) {
|
||||
setState(() {
|
||||
@@ -178,17 +193,6 @@ class _SessionScreenState extends State<SessionScreen> {
|
||||
void _onStepCompleted() {
|
||||
_triggerFeedback();
|
||||
if (_currentStepIndex + 1 < _steps.length) {
|
||||
final nextStep = _steps[_currentStepIndex + 1];
|
||||
if (_settings.enableVoicePrompt) {
|
||||
if (nextStep.type == StepType.crossDrugWait) {
|
||||
TtsService().speak('两药间隔开始,请等待五分钟');
|
||||
} else if (nextStep.type == StepType.inhale) {
|
||||
final medName = nextStep.canister?.name.split(" ")[0] ?? '药物';
|
||||
TtsService().speak('请吸入$medName第${nextStep.puffIndex}喷');
|
||||
} else if (nextStep.type == StepType.intraPuffWait) {
|
||||
TtsService().speak('请等待三十秒后喷第二喷');
|
||||
}
|
||||
}
|
||||
_startStep(_currentStepIndex + 1);
|
||||
} else {
|
||||
_finishSession();
|
||||
|
||||
Reference in New Issue
Block a user