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