Fix voice input for iOS Safari and prevent infinite loop
- 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:
@@ -30,16 +30,52 @@ export async function POST(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
} else if (contentType.includes('multipart/form-data')) {
|
||||
// Audio file upload (needs transcription)
|
||||
// TODO: Implement Whisper API integration for audio transcription
|
||||
// For now, return not implemented
|
||||
// Audio file upload - forward to backend for Whisper transcription
|
||||
const formData = await request.formData();
|
||||
const audioFile = formData.get('audio');
|
||||
|
||||
if (!audioFile) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: 'VOICE_NO_AUDIO',
|
||||
message: 'No audio file provided',
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Forward to backend
|
||||
const backendUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3020';
|
||||
const backendFormData = new FormData();
|
||||
backendFormData.append('audio', audioFile);
|
||||
|
||||
const backendResponse = await fetch(`${backendUrl}/api/v1/voice/transcribe`, {
|
||||
method: 'POST',
|
||||
body: backendFormData,
|
||||
headers: {
|
||||
// Forward auth token if present
|
||||
...(request.headers.get('authorization') && {
|
||||
authorization: request.headers.get('authorization')!,
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
if (!backendResponse.ok) {
|
||||
const errorData = await backendResponse.json();
|
||||
return NextResponse.json(errorData, { status: backendResponse.status });
|
||||
}
|
||||
|
||||
const result = await backendResponse.json();
|
||||
|
||||
// Backend returns { success, transcript, classification }
|
||||
// Return in the format expected by the frontend
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: 'VOICE_AUDIO_NOT_IMPLEMENTED',
|
||||
message: 'Audio transcription not yet implemented. Use text input for now.',
|
||||
hint: 'Send JSON with { "text": "your voice command" }',
|
||||
success: true,
|
||||
transcript: result.transcript,
|
||||
classification: result.classification,
|
||||
},
|
||||
{ status: 501 }
|
||||
{ status: 200 }
|
||||
);
|
||||
} else {
|
||||
return NextResponse.json(
|
||||
|
||||
Reference in New Issue
Block a user