🕐 커밋 시간: 2025. 10. 17. 17:14:07 📊 변경 통계: • 총 파일: 9개 • 추가: +201줄 • 삭제: -45줄 📁 추가된 파일: + com.twin.app.shoptime/ai_poc_list.json + com.twin.app.shoptime/src/constants/featureFlags.js 📝 수정된 파일: ~ com.twin.app.shoptime/src/App/App.js ~ com.twin.app.shoptime/src/actions/voiceActions.js ~ com.twin.app.shoptime/src/components/TabLayout/TabLayout.jsx ~ com.twin.app.shoptime/src/hooks/useSearchVoice.js ~ com.twin.app.shoptime/src/views/MainView/MainView.jsx ~ com.twin.app.shoptime/src/views/SearchPanel/SearchPanel.new.jsx ~ com.twin.app.shoptime/src/views/SearchPanel/VoiceInputOverlay/VoiceInputOverlay.jsx 🔧 함수 변경 내용: 📄 com.twin.app.shoptime/src/App/App.js (javascript): 🔄 Modified: function() 📄 com.twin.app.shoptime/src/actions/voiceActions.js (javascript): ✅ Added: addLog() 🔧 주요 변경 내용: • 핵심 비즈니스 로직 개선 • UI 컴포넌트 아키텍처 개선
56 lines
1.8 KiB
JavaScript
56 lines
1.8 KiB
JavaScript
// src/hooks/useSearchVoice.js
|
|
|
|
import { useEffect } from 'react';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import { registerVoiceFramework, unregisterVoiceFramework } from '../actions/voiceActions';
|
|
import { FEATURE_FLAGS } from '../constants/featureFlags';
|
|
|
|
/**
|
|
* SearchPanel용 음성 입력 Hook
|
|
* - SearchPanel이 foreground일 때 voice framework 등록
|
|
* - STT 텍스트를 자동으로 searchQuery로 설정
|
|
*
|
|
* @param {boolean} isOnTop - SearchPanel이 foreground 상태인지 여부
|
|
* @param {function} onSTTText - STT 텍스트 수신 시 호출될 콜백 함수
|
|
*/
|
|
export const useSearchVoice = (isOnTop, onSTTText) => {
|
|
const dispatch = useDispatch();
|
|
const { lastSTTText, sttTimestamp } = useSelector((state) => state.voice);
|
|
|
|
// SearchPanel이 foreground일 때만 voice 등록
|
|
useEffect(() => {
|
|
// VUI 비활성화 시 실행 안함
|
|
if (!FEATURE_FLAGS.ENABLE_VUI) {
|
|
console.log('[useSearchVoice] VUI disabled by feature flag');
|
|
return;
|
|
}
|
|
|
|
if (isOnTop) {
|
|
console.log('[useSearchVoice] Registering voice framework');
|
|
dispatch(registerVoiceFramework());
|
|
} else {
|
|
console.log('[useSearchVoice] Unregistering voice framework');
|
|
dispatch(unregisterVoiceFramework());
|
|
}
|
|
|
|
// Cleanup on unmount
|
|
return () => {
|
|
dispatch(unregisterVoiceFramework());
|
|
};
|
|
}, [isOnTop, dispatch]);
|
|
|
|
// STT 텍스트 수신 처리
|
|
useEffect(() => {
|
|
// VUI 비활성화 시에도 Web Speech API의 STT는 처리
|
|
// (Web Speech도 VOICE_STT_TEXT_RECEIVED 액션을 사용)
|
|
if (lastSTTText && sttTimestamp) {
|
|
console.log('[useSearchVoice] STT text received:', lastSTTText);
|
|
if (onSTTText) {
|
|
onSTTText(lastSTTText);
|
|
}
|
|
}
|
|
}, [lastSTTText, sttTimestamp, onSTTText]);
|
|
};
|
|
|
|
export default useSearchVoice;
|