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:
parent
d63124203b
commit
d1ab67e60e
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue