Fix updateVoiceApiType function and add API logging
Fixes error: "updateVoiceApiType is not a function" Changes: - Add voiceApiType state to VoiceContext - Implement updateVoiceApiType callback - Load saved voice API type from SecureStore on mount - Use voiceApiType in sendTranscript (instead of hardcoded 'ask_wellnuo_ai') - Add console.log showing which API type is being used - Export voiceApiType and updateVoiceApiType in context provider Now Voice API selector in Profile works correctly and logs show which API function (voice_ask or ask_wellnuo_ai) is being called.
This commit is contained in:
parent
d6353c8533
commit
0881a9565d
@ -134,6 +134,10 @@ interface VoiceContextValue {
|
|||||||
stopSpeaking: () => void;
|
stopSpeaking: () => void;
|
||||||
// Interrupt TTS if speaking (call when user starts talking)
|
// Interrupt TTS if speaking (call when user starts talking)
|
||||||
interruptIfSpeaking: () => boolean;
|
interruptIfSpeaking: () => boolean;
|
||||||
|
|
||||||
|
// Voice API configuration
|
||||||
|
voiceApiType: 'voice_ask' | 'ask_wellnuo_ai';
|
||||||
|
updateVoiceApiType: (type: 'voice_ask' | 'ask_wellnuo_ai') => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const VoiceContext = createContext<VoiceContextValue | undefined>(undefined);
|
const VoiceContext = createContext<VoiceContextValue | undefined>(undefined);
|
||||||
@ -162,6 +166,19 @@ export function VoiceProvider({ children }: { children: ReactNode }) {
|
|||||||
// Deployment ID from settings
|
// Deployment ID from settings
|
||||||
const deploymentIdRef = useRef<string | null>(null);
|
const deploymentIdRef = useRef<string | null>(null);
|
||||||
|
|
||||||
|
// Voice API type (voice_ask or ask_wellnuo_ai)
|
||||||
|
const [voiceApiType, setVoiceApiType] = useState<'voice_ask' | 'ask_wellnuo_ai'>('ask_wellnuo_ai');
|
||||||
|
|
||||||
|
// Load voice API type on mount
|
||||||
|
React.useEffect(() => {
|
||||||
|
const loadVoiceApiType = async () => {
|
||||||
|
const savedType = await api.getVoiceApiType();
|
||||||
|
setVoiceApiType(savedType);
|
||||||
|
console.log('[VoiceContext] Loaded voice API type:', savedType);
|
||||||
|
};
|
||||||
|
loadVoiceApiType();
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Load deployment ID on mount
|
// Load deployment ID on mount
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const loadDeploymentId = async () => {
|
const loadDeploymentId = async () => {
|
||||||
@ -172,6 +189,15 @@ export function VoiceProvider({ children }: { children: ReactNode }) {
|
|||||||
loadDeploymentId();
|
loadDeploymentId();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update voice API type (voice_ask or ask_wellnuo_ai)
|
||||||
|
*/
|
||||||
|
const updateVoiceApiType = useCallback(async (type: 'voice_ask' | 'ask_wellnuo_ai') => {
|
||||||
|
console.log('[VoiceContext] Updating voice API type to:', type);
|
||||||
|
setVoiceApiType(type);
|
||||||
|
await api.setVoiceApiType(type);
|
||||||
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get WellNuo API token (same as chat.tsx)
|
* Get WellNuo API token (same as chat.tsx)
|
||||||
*/
|
*/
|
||||||
@ -249,9 +275,12 @@ export function VoiceProvider({ children }: { children: ReactNode }) {
|
|||||||
// Get deployment ID
|
// Get deployment ID
|
||||||
const deploymentId = deploymentIdRef.current || '21';
|
const deploymentId = deploymentIdRef.current || '21';
|
||||||
|
|
||||||
|
// Log which API type we're using
|
||||||
|
console.log('[VoiceContext] Using API type:', voiceApiType);
|
||||||
|
|
||||||
// Build request params
|
// Build request params
|
||||||
const requestParams: Record<string, string> = {
|
const requestParams: Record<string, string> = {
|
||||||
function: 'ask_wellnuo_ai',
|
function: voiceApiType, // Use the selected voiceApiType
|
||||||
clientId: 'MA_001',
|
clientId: 'MA_001',
|
||||||
user_name: WELLNUO_USER,
|
user_name: WELLNUO_USER,
|
||||||
token: token,
|
token: token,
|
||||||
@ -313,7 +342,7 @@ export function VoiceProvider({ children }: { children: ReactNode }) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[getWellNuoToken, addTranscriptEntry]
|
[getWellNuoToken, addTranscriptEntry, voiceApiType]
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -454,6 +483,8 @@ export function VoiceProvider({ children }: { children: ReactNode }) {
|
|||||||
speak,
|
speak,
|
||||||
stopSpeaking,
|
stopSpeaking,
|
||||||
interruptIfSpeaking,
|
interruptIfSpeaking,
|
||||||
|
voiceApiType,
|
||||||
|
updateVoiceApiType,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user