|
|
|
@ -1,4 +1,5 @@ |
|
|
|
import 'dart:async'; |
|
|
|
import 'package:amap_flutter/amap_flutter.dart'; |
|
|
|
import 'package:deep_voice/data/services/spotify_service.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:flutter/widgets.dart'; |
|
|
|
@ -32,6 +33,11 @@ class ChatController extends GetxController { |
|
|
|
// 添加ScrollController用于控制列表滚动 |
|
|
|
final ScrollController scrollController = ScrollController(); |
|
|
|
|
|
|
|
final _amapFlutter = AmapFlutter(); |
|
|
|
StreamSubscription? _locationStream; |
|
|
|
String _latLng = ''; |
|
|
|
String _city = ''; |
|
|
|
|
|
|
|
// Agent 信息 |
|
|
|
late final Agent agent; |
|
|
|
|
|
|
|
@ -170,6 +176,8 @@ class ChatController extends GetxController { |
|
|
|
// 订阅VoiceInteractionService事件 |
|
|
|
_subscribeToVoiceInteractionEvents(); |
|
|
|
|
|
|
|
_getLocation(); |
|
|
|
|
|
|
|
player.playerStateStream.listen((state) async { |
|
|
|
if (state.processingState == ProcessingState.completed) { |
|
|
|
await player.seek(Duration.zero); |
|
|
|
@ -184,6 +192,16 @@ class ChatController extends GetxController { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
void _getLocation() async { |
|
|
|
await _amapFlutter.initLocation(); |
|
|
|
_locationStream = _amapFlutter.locationStream().listen((data) async { |
|
|
|
_latLng = '${data['longitude']},${data['latitude']}}'; |
|
|
|
_city = data['city']; |
|
|
|
_amapFlutter.stopLocation(); |
|
|
|
}); |
|
|
|
_amapFlutter.startLocation(); |
|
|
|
} |
|
|
|
|
|
|
|
/// 订阅VoiceInteractionService事件 |
|
|
|
void _subscribeToVoiceInteractionEvents() { |
|
|
|
if (_voiceInteractionService.eventStream != null) { |
|
|
|
@ -265,6 +283,9 @@ class ChatController extends GetxController { |
|
|
|
_autoStopTimer?.cancel(); |
|
|
|
_scrollDebounceTimer?.cancel(); // 清理防抖计时器 |
|
|
|
|
|
|
|
_amapFlutter.dispose(); |
|
|
|
_locationStream?.cancel(); |
|
|
|
|
|
|
|
// 停止TTS |
|
|
|
_ttsService.stop(); |
|
|
|
|
|
|
|
@ -432,6 +453,12 @@ class ChatController extends GetxController { |
|
|
|
'role': m.role, |
|
|
|
'content': m.content, |
|
|
|
}); |
|
|
|
if (i == recentMessages.length - 2) { |
|
|
|
messageHistory.add({ |
|
|
|
'role': 'user', |
|
|
|
'content': '我当前在$_city,我的经纬度是$_latLng', |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return messageHistory; |
|
|
|
|