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;
|
||||
// Interrupt TTS if speaking (call when user starts talking)
|
||||
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);
|
||||
@ -162,6 +166,19 @@ export function VoiceProvider({ children }: { children: ReactNode }) {
|
||||
// Deployment ID from settings
|
||||
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
|
||||
React.useEffect(() => {
|
||||
const loadDeploymentId = async () => {
|
||||
@ -172,6 +189,15 @@ export function VoiceProvider({ children }: { children: ReactNode }) {
|
||||
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)
|
||||
*/
|
||||
@ -249,9 +275,12 @@ export function VoiceProvider({ children }: { children: ReactNode }) {
|
||||
// Get deployment ID
|
||||
const deploymentId = deploymentIdRef.current || '21';
|
||||
|
||||
// Log which API type we're using
|
||||
console.log('[VoiceContext] Using API type:', voiceApiType);
|
||||
|
||||
// Build request params
|
||||
const requestParams: Record<string, string> = {
|
||||
function: 'ask_wellnuo_ai',
|
||||
function: voiceApiType, // Use the selected voiceApiType
|
||||
clientId: 'MA_001',
|
||||
user_name: WELLNUO_USER,
|
||||
token: token,
|
||||
@ -313,7 +342,7 @@ export function VoiceProvider({ children }: { children: ReactNode }) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
[getWellNuoToken, addTranscriptEntry]
|
||||
[getWellNuoToken, addTranscriptEntry, voiceApiType]
|
||||
);
|
||||
|
||||
/**
|
||||
@ -454,6 +483,8 @@ export function VoiceProvider({ children }: { children: ReactNode }) {
|
||||
speak,
|
||||
stopSpeaking,
|
||||
interruptIfSpeaking,
|
||||
voiceApiType,
|
||||
updateVoiceApiType,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user