Skip to content

feat: share speach profile#4650

Draft
dluffy56 wants to merge 9 commits intoBasedHardware:mainfrom
dluffy56:feat/share-speach-profile
Draft

feat: share speach profile#4650
dluffy56 wants to merge 9 commits intoBasedHardware:mainfrom
dluffy56:feat/share-speach-profile

Conversation

@dluffy56
Copy link
Contributor

@dluffy56 dluffy56 commented Feb 7, 2026

Issue #3040

Description

Adds support for sharing speech profiles between users

dluffy56 and others added 9 commits January 23, 2026 02:12
… it for shared profiles

  Previously shared profiles loaded the sharer's contacts instead of their
  own voice. Now we extract and store an embedding when a user uploads
  their speech profile, and load that embedding during transcription for
  shared profile speaker identification. Also removes the broken persistent
  speaker_id mapping that incorrectly cached session-local IDs across sessions.
  - Merge speech_profile_sharing.dart into speech_profile.dart
  - Add Pydantic model for share/revoke request body
  - Validate target user exists before sharing
  - Remove dead get_user_speaker_embedding function
  - Use single Firestore read per shared owner in transcription
  - Add l10n keys for sharing UI strings
  - Add Logger.debug to Dart API functions
  - Fix indentation and EOF newlines
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new feature for sharing speech profiles between users. It adds the necessary backend API endpoints for sharing, revoking, and listing shared profiles, along with corresponding UI elements in the mobile app. The backend is also updated to extract and utilize speaker embeddings from both user-owned and shared profiles for improved speaker identification. The implementation is solid, but the identified high-severity issues related to database query efficiency and error handling still need to be addressed.

Comment on lines +1052 to +1058
docs = shared_ref.stream()
shared = []
for doc in docs:
data = doc.to_dict()
if not data.get('revoked_at'):
shared.append(data['shared_with_uid'])
return shared
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This implementation fetches all sharing documents for a user and then filters them in Python to find the non-revoked ones. This is inefficient as it can lead to reading many unnecessary documents from Firestore. It's better to apply a filter directly in the query to only fetch the relevant documents, which is more performant and cost-effective.

Suggested change
docs = shared_ref.stream()
shared = []
for doc in docs:
data = doc.to_dict()
if not data.get('revoked_at'):
shared.append(data['shared_with_uid'])
return shared
shares_query = shared_ref.where(filter=firestore.FieldFilter('revoked_at', '==', None))
return [doc.to_dict()['shared_with_uid'] for doc in shares_query.stream()]

Comment on lines +87 to +88
except Exception as e:
print(f"Failed to extract speaker embedding during profile upload: {e}", uid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Catching a broad except Exception is risky as it can hide bugs and swallow system-level exceptions (e.g., KeyboardInterrupt). It's better to catch more specific exceptions that you expect to handle, such as those related to network requests or database operations. Additionally, using print for logging errors is not ideal for production environments. A structured logger should be used to provide more context and allow for better error tracking and monitoring.

Comment on lines +1280 to +1281
except Exception as e:
print(f"Failed to load shared profile from {owner_uid}: {e}", uid, session_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to another comment, using a broad except Exception can mask underlying issues and make debugging difficult. It's recommended to catch more specific exceptions, for instance, those related to Firestore database operations when calling user_db.get_user_profile. Also, print is not suitable for production-level error logging; a dedicated logging library would provide better observability and error management.

@dluffy56
Copy link
Contributor Author

dluffy56 commented Feb 7, 2026

working on these and tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant