Fix real-time speech recognition display

1. Update UI to show actual _currentText instead of fixed 'realtime recognizing...' text
   - Use Flexible widget to handle text overflow
   - Show actual recognition text when available
   - Fallback to 'realtime recognizing...' when text is empty

2. Fix final result processing logic
   - Don't update _currentText when processing final results
   - Final results only append to text field, don't interfere with real-time display

3. Improve listening status management
   - Clear _currentText when recording stops
   - Ensure clean state transitions between recording sessions

This fixes the issue where users could only see final results without real-time feedback.
This commit is contained in:
Max 2025-09-09 11:22:37 +08:00
parent d63124203b
commit d1ab67e60e
1 changed files with 13 additions and 7 deletions

View File

@ -359,13 +359,17 @@ class _SpeechRecognitionPageState extends State<SpeechRecognitionPage> {
children: [
Icon(Icons.mic, size: 14, color: Colors.blue[600]),
const SizedBox(width: 4),
Text(
'实时识别中...',
Flexible(
child: Text(
_currentText.isEmpty ? '实时识别中...' : _currentText,
style: TextStyle(
fontSize: 12,
color: Colors.blue[600],
fontWeight: FontWeight.w500,
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
],
),
@ -476,7 +480,7 @@ class _SpeechRecognitionPageState extends State<SpeechRecognitionPage> {
currentTextInBox += ' '; //
}
_textController.text = currentTextInBox + result.recognizedWords;
_currentText = result.recognizedWords; //
// _currentText
} else {
//
print('📱 [Example] 实时识别: ${result.recognizedWords}');
@ -505,6 +509,8 @@ class _SpeechRecognitionPageState extends State<SpeechRecognitionPage> {
if (_recognitionHistory.length > 10) {
_recognitionHistory.removeLast();
}
//
_currentText = '';
});
}
} else {