diff --git a/example/lib/main.dart b/example/lib/main.dart index fbf30da..ac7e671 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -359,12 +359,16 @@ class _SpeechRecognitionPageState extends State { children: [ Icon(Icons.mic, size: 14, color: Colors.blue[600]), const SizedBox(width: 4), - Text( - '实时识别中...', - style: TextStyle( - fontSize: 12, - color: Colors.blue[600], - fontWeight: FontWeight.w500, + 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 { currentTextInBox += ' '; // 添加空格分隔 } _textController.text = currentTextInBox + result.recognizedWords; - _currentText = result.recognizedWords; // 保存当前识别结果 + // 最终结果不需要更新_currentText,因为录音已结束 } else { // 实时结果:仅用于显示,不追加到文本框 print('📱 [Example] 实时识别: ${result.recognizedWords}'); @@ -505,6 +509,8 @@ class _SpeechRecognitionPageState extends State { if (_recognitionHistory.length > 10) { _recognitionHistory.removeLast(); } + // 清空当前文本,因为录音已结束 + _currentText = ''; }); } } else {