Fix voice input for iOS Safari and prevent infinite loop
Some checks failed
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled

- Remove temperature parameter from GPT-5-mini activity extraction (not supported)
- Add classification state to useVoiceInput hook to avoid duplicate API calls
- Prevent infinite loop in VoiceFloatingButton by tracking lastClassifiedTranscript
- Use classification from backend directly instead of making second request
- iOS Safari now successfully transcribes with Azure Whisper and classifies with GPT-5-mini

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-02 07:15:44 +00:00
parent 46167a8307
commit a44faf6ef4
4 changed files with 72 additions and 14 deletions

View File

@@ -1,4 +1,5 @@
import { useState, useEffect, useCallback, useRef } from 'react';
import { tokenStorage } from '@/lib/utils/tokenStorage';
export interface VoiceInputResult {
transcript: string;
@@ -10,6 +11,7 @@ export interface VoiceInputState {
isListening: boolean;
isSupported: boolean;
transcript: string;
classification: any | null;
error: string | null;
usesFallback: boolean;
}
@@ -25,6 +27,7 @@ export function useVoiceInput() {
isListening: false,
isSupported: false,
transcript: '',
classification: null,
error: null,
usesFallback: false,
});
@@ -148,9 +151,19 @@ export function useVoiceInput() {
formData.append('audio', audioBlob, `recording.${extension}`);
console.log('[Voice] Sending to backend for transcription...');
const response = await fetch('/api/voice/transcribe', {
// Get auth token and API base URL
const token = tokenStorage.getAccessToken();
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3020';
const headers: HeadersInit = {};
if (token) {
headers['Authorization'] = `Bearer ${token}`;
}
const response = await fetch(`${API_BASE_URL}/api/v1/voice/transcribe`, {
method: 'POST',
body: formData,
headers,
});
console.log('[Voice] Transcription response status:', response.status);
@@ -162,6 +175,7 @@ export function useVoiceInput() {
...prev,
isListening: false,
transcript: data.transcript,
classification: data.classification || null,
}));
} else {
console.error('[Voice] Transcription failed:', data);
@@ -169,6 +183,7 @@ export function useVoiceInput() {
...prev,
isListening: false,
error: data.message || 'Failed to transcribe audio',
classification: null,
}));
}
} catch (error) {
@@ -358,6 +373,7 @@ export function useVoiceInput() {
setState(prev => ({
...prev,
transcript: '',
classification: null,
error: null,
}));
}, []);