Skip to content

Commit

Permalink
Fix stream transcript function, remove redundant param (#1169)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
	- Improved efficiency in audio segment processing.
	- Enhanced error handling for WebSocket connections.
	- Restricted item dismissal during syncing to improve user experience.
	- Added a new property to track V2 device connection status.

- **Bug Fixes**
	- Adjusted handling of audio segment timings for better alignment.
	- Improved navigation control during syncing operations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
beastoin authored Oct 25, 2024
2 parents 466081a + 516a38f commit f289a7d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/lib/pages/memories/sync_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class _WalListItemState extends State<WalListItem> {
borderRadius: BorderRadius.circular(16.0),
child: Dismissible(
key: Key(widget.wal.id),
direction: DismissDirection.endToStart,
direction: widget.wal.isSyncing ? DismissDirection.none : DismissDirection.endToStart,
background: Container(
alignment: Alignment.centerRight,
padding: const EdgeInsets.only(right: 20.0),
Expand Down
5 changes: 3 additions & 2 deletions app/lib/pages/settings/device_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:friend_private/backend/preferences.dart';
import 'package:friend_private/backend/schema/bt_device/bt_device.dart';
import 'package:friend_private/pages/home/firmware_update.dart';
import 'package:friend_private/pages/memories/sync_page.dart';
import 'package:friend_private/pages/sdcard/page.dart';
import 'package:friend_private/providers/device_provider.dart';
import 'package:friend_private/providers/onboarding_provider.dart';
import 'package:friend_private/services/services.dart';
Expand Down Expand Up @@ -160,6 +159,8 @@ class _DeviceSettingsState extends State<DeviceSettings> {
}

List<Widget> deviceSettingsWidgets(BtDevice? device, BuildContext context) {
var provider = Provider.of<DeviceProvider>(context, listen: true);

return [
ListTile(
title: const Text('Device Name'),
Expand All @@ -184,7 +185,7 @@ List<Widget> deviceSettingsWidgets(BtDevice? device, BuildContext context) {
),
GestureDetector(
onTap: () {
if (!SharedPreferencesUtil().deviceIsV2) {
if (!provider.isDeviceV2Connected) {
showDialog(
context: context,
builder: (c) => getDialog(
Expand Down
22 changes: 22 additions & 0 deletions app/lib/providers/device_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption

bool isConnecting = false;
bool isConnected = false;
bool isDeviceV2Connected = false;
BtDevice? connectedDevice;
BtDevice? pairedDevice;
StreamSubscription<List<int>>? _bleBatteryLevelListener;
Expand Down Expand Up @@ -73,6 +74,14 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
}
}

Future<List<int>> _getStorageList(String deviceId) async {
var connection = await ServiceManager.instance().device.ensureConnection(deviceId);
if (connection == null) {
return [];
}
return connection.getStorageList();
}

Future<BtDevice?> _getConnectedDevice() async {
var deviceId = SharedPreferencesUtil().btDevice.id;
if (deviceId.isEmpty) {
Expand Down Expand Up @@ -157,6 +166,7 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
var cDevice = await _getConnectedDevice();
if (cDevice != null) {
setConnectedDevice(cDevice);
setIsDeviceV2Connected();
// SharedPreferencesUtil().btDevice = cDevice;
SharedPreferencesUtil().deviceName = cDevice.name;
MixpanelManager().deviceConnected();
Expand Down Expand Up @@ -200,6 +210,7 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
void onDeviceDisconnected() async {
debugPrint('onDisconnected inside: $connectedDevice');
setConnectedDevice(null);
setIsDeviceV2Connected();
setIsConnected(false);
updateConnectingStatus(false);

Expand Down Expand Up @@ -231,6 +242,7 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
_disconnectNotificationTimer?.cancel();
NotificationService.instance.clearNotification(1);
setConnectedDevice(device);
setIsDeviceV2Connected();
setIsConnected(true);
if (isConnected) {
await initiateBleBatteryListener();
Expand All @@ -247,6 +259,16 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
notifyListeners();
}

Future setIsDeviceV2Connected() async {
if (connectedDevice == null) {
isDeviceV2Connected = false;
} else {
var storageFiles = await _getStorageList(connectedDevice!.id);
isDeviceV2Connected = storageFiles.isNotEmpty;
}
notifyListeners();
}

@override
void onDeviceConnectionStateChanged(String deviceId, DeviceConnectionState state) async {
debugPrint("provider > device connection state changed...${deviceId}...${state}...${connectedDevice?.id}");
Expand Down
2 changes: 1 addition & 1 deletion backend/routers/transcribe_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async def create_memory_on_segment_received_task(finished_at: datetime):
memory_creation_task = asyncio.create_task(
_trigger_create_memory_with_delay(memory_creation_timeout, finished_at))

def stream_transcript(segments, _):
def stream_transcript(segments):
nonlocal websocket
nonlocal seconds_to_trim

Expand Down

0 comments on commit f289a7d

Please sign in to comment.