11import { useDigitalHumanStore } from '../../store/digitalHumanStore' ;
2+ import { digitalHumanEngine } from '../avatar/DigitalHumanEngine' ;
23import { sendUserInput } from '../dialogue/dialogueService' ;
34import { handleDialogueResponse } from '../dialogue/dialogueOrchestrator' ;
45
@@ -108,7 +109,7 @@ export class TTSService {
108109 this . synth . cancel ( ) ;
109110 this . isProcessingQueue = false ;
110111 useDigitalHumanStore . getState ( ) . setSpeaking ( false ) ;
111- useDigitalHumanStore . getState ( ) . setBehavior ( 'idle' ) ;
112+ digitalHumanEngine . setBehavior ( 'idle' ) ;
112113 }
113114
114115 // 语音合成 - 支持队列
@@ -177,22 +178,22 @@ export class TTSService {
177178
178179 utterance . onstart = ( ) => {
179180 useDigitalHumanStore . getState ( ) . setSpeaking ( true ) ;
180- useDigitalHumanStore . getState ( ) . setBehavior ( 'speaking' ) ;
181+ digitalHumanEngine . setBehavior ( 'speaking' ) ;
181182 } ;
182183
183184 utterance . onend = ( ) => {
184185 // 只有队列为空时才重置状态
185186 if ( this . speechQueue . length === 0 ) {
186187 useDigitalHumanStore . getState ( ) . setSpeaking ( false ) ;
187- useDigitalHumanStore . getState ( ) . setBehavior ( 'idle' ) ;
188+ digitalHumanEngine . setBehavior ( 'idle' ) ;
188189 }
189190 resolve ( ) ;
190191 } ;
191192
192193 utterance . onerror = ( event ) => {
193194 console . error ( '语音合成错误:' , event ) ;
194195 useDigitalHumanStore . getState ( ) . setSpeaking ( false ) ;
195- useDigitalHumanStore . getState ( ) . setBehavior ( 'idle' ) ;
196+ digitalHumanEngine . setBehavior ( 'idle' ) ;
196197 useDigitalHumanStore . getState ( ) . addError ( `语音合成失败: ${ event . error } ` ) ;
197198 reject ( new Error ( event . error ) ) ;
198199 } ;
@@ -355,7 +356,7 @@ export class ASRService {
355356
356357 this . recognition . onstart = ( ) => {
357358 this . isRunning = true ;
358- useDigitalHumanStore . getState ( ) . setBehavior ( 'listening' ) ;
359+ digitalHumanEngine . setBehavior ( 'listening' ) ;
359360 this . callbacks . onStart ?.( ) ;
360361 } ;
361362
@@ -450,7 +451,7 @@ export class ASRService {
450451 this . clearTimeout ( ) ;
451452 this . isRunning = false ;
452453 useDigitalHumanStore . getState ( ) . setRecording ( false ) ;
453- useDigitalHumanStore . getState ( ) . setBehavior ( 'idle' ) ;
454+ digitalHumanEngine . setBehavior ( 'idle' ) ;
454455 }
455456
456457 async start ( options ?: ASRStartOptions ) : Promise < boolean > {
@@ -523,7 +524,7 @@ export class ASRService {
523524 this . mode = 'command' ;
524525 this . isRunning = false ;
525526 useDigitalHumanStore . getState ( ) . setRecording ( false ) ;
526- useDigitalHumanStore . getState ( ) . setBehavior ( 'idle' ) ;
527+ digitalHumanEngine . setBehavior ( 'idle' ) ;
527528 }
528529
529530 abort ( ) : void {
@@ -604,7 +605,7 @@ export class ASRService {
604605 const store = useDigitalHumanStore . getState ( ) ;
605606
606607 store . setLoading ( true ) ;
607- store . setBehavior ( 'thinking' ) ;
608+ digitalHumanEngine . setBehavior ( 'thinking' ) ;
608609 store . addChatMessage ( 'user' , text ) ;
609610
610611 try {
@@ -621,7 +622,7 @@ export class ASRService {
621622 } catch ( error : unknown ) {
622623 console . error ( '对话服务错误:' , error ) ;
623624 store . addError ( '对话服务暂时不可用,请稍后重试' ) ;
624- store . setBehavior ( 'idle' ) ;
625+ digitalHumanEngine . setBehavior ( 'idle' ) ;
625626
626627 // 本地降级回复
627628 const fallbackReply = '抱歉,我暂时无法处理您的请求,请稍后再试。' ;
@@ -636,75 +637,63 @@ export class ASRService {
636637
637638 // 预设动作:打招呼
638639 performGreeting ( ) : void {
639- const store = useDigitalHumanStore . getState ( ) ;
640- store . setEmotion ( 'happy' ) ;
641- store . setExpression ( 'smile' ) ;
642- store . setBehavior ( 'greeting' ) ;
643- store . setAnimation ( 'wave' ) ;
640+ digitalHumanEngine . setEmotion ( 'happy' ) ;
641+ digitalHumanEngine . setExpression ( 'smile' ) ;
642+ digitalHumanEngine . playAnimation ( 'wave' ) ;
644643
645644 this . tts . speak ( '您好!很高兴见到您!有什么可以帮助您的吗?' ) ;
646645
647646 setTimeout ( ( ) => {
648- store . setEmotion ( 'neutral' ) ;
649- store . setExpression ( 'neutral' ) ;
650- store . setBehavior ( 'idle' ) ;
651- store . setAnimation ( 'idle' ) ;
647+ digitalHumanEngine . setEmotion ( 'neutral' ) ;
648+ digitalHumanEngine . setExpression ( 'neutral' ) ;
649+ digitalHumanEngine . setBehavior ( 'idle' ) ;
652650 } , 4000 ) ;
653651 }
654652
655653 // 预设动作:跳舞
656654 performDance ( ) : void {
657- const store = useDigitalHumanStore . getState ( ) ;
658- store . setAnimation ( 'dance' ) ;
659- store . setBehavior ( 'excited' ) ;
660- store . setEmotion ( 'happy' ) ;
655+ digitalHumanEngine . setEmotion ( 'happy' ) ;
656+ digitalHumanEngine . playAnimation ( 'dance' ) ;
661657
662658 this . tts . speak ( '让我为您跳一支舞!' ) ;
663659
664660 setTimeout ( ( ) => {
665- store . setAnimation ( 'idle' ) ;
666- store . setBehavior ( 'idle' ) ;
667- store . setEmotion ( 'neutral' ) ;
661+ digitalHumanEngine . setEmotion ( 'neutral' ) ;
662+ digitalHumanEngine . setBehavior ( 'idle' ) ;
668663 } , 6000 ) ;
669664 }
670665
671666 // 预设动作:点头
672667 performNod ( ) : void {
673- const store = useDigitalHumanStore . getState ( ) ;
674- store . setAnimation ( 'nod' ) ;
675- store . setBehavior ( 'listening' ) ;
668+ digitalHumanEngine . playAnimation ( 'nod' ) ;
676669
677670 this . tts . speak ( '好的,我明白了。' ) ;
678671
679672 setTimeout ( ( ) => {
680- store . setAnimation ( 'idle' ) ;
681- store . setBehavior ( 'idle' ) ;
673+ digitalHumanEngine . setBehavior ( 'idle' ) ;
682674 } , 2000 ) ;
683675 }
684676
685677 // 预设动作:摇头
686678 performShakeHead ( ) : void {
687- const store = useDigitalHumanStore . getState ( ) ;
688- store . setAnimation ( 'shakeHead' ) ;
679+ digitalHumanEngine . playAnimation ( 'shakeHead' ) ;
689680
690681 this . tts . speak ( '不太确定呢。' ) ;
691682
692683 setTimeout ( ( ) => {
693- store . setAnimation ( 'idle' ) ;
684+ digitalHumanEngine . setBehavior ( 'idle' ) ;
694685 } , 2000 ) ;
695686 }
696687
697688 // 预设动作:思考
698689 performThinking ( ) : void {
699- const store = useDigitalHumanStore . getState ( ) ;
700- store . setBehavior ( 'thinking' ) ;
701- store . setAnimation ( 'think' ) ;
690+ digitalHumanEngine . setBehavior ( 'thinking' ) ;
691+ digitalHumanEngine . playAnimation ( 'think' ) ;
702692
703693 this . tts . speak ( '让我想想...' ) ;
704694
705695 setTimeout ( ( ) => {
706- store . setBehavior ( 'idle' ) ;
707- store . setAnimation ( 'idle' ) ;
696+ digitalHumanEngine . setBehavior ( 'idle' ) ;
708697 } , 3000 ) ;
709698 }
710699}
0 commit comments