Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify capture provider whenever language changed #1000

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

beastoin
Copy link
Collaborator

@beastoin beastoin commented Oct 8, 2024

Summary by Entelligence.AI

  • New Feature: Enhanced the language setting functionality in the application. Now, when the recording language is changed, it will be reflected in the socket connections, ensuring that the communication is carried out in the specified language.
  • Refactor: Updated function signatures in the SocketServicePool class to include a language parameter, allowing for more precise control over socket service creation.
  • Chore: Removed an unnecessary import statement from speech_profile_provider.dart, improving code cleanliness and maintainability.

@beastoin beastoin merged commit 3f22b86 into main Oct 8, 2024
1 check passed
@beastoin beastoin deleted the bgioy_language_sheet branch October 8, 2024 03:28
Copy link

github-actions bot commented Oct 8, 2024

Image description Entelligence.AI

Walkthrough

This update enhances the language setting functionality in the application. It ensures that changes in recording language are propagated to the CaptureProvider and considered when establishing socket connections. The external interface of the code has been updated to allow specification of a language when creating socket services.

Changes

File(s) Summary
app/lib/pages/home/page.dart,
app/lib/providers/capture_provider.dart,
app/lib/services/sockets.dart,
app/lib/services/sockets/transcription_connection.dart
These changes ensure that the CaptureProvider is notified when the recording language is changed, and this information is used when establishing socket connections. The SocketServicePool class now includes a language parameter, allowing for the specification of a language when creating socket services.
app/lib/providers/speech_profile_provider.dart Removed an unnecessary import statement for memories.dart.

🎉 Here's to the code that grows, 🌱

With each commit, its knowledge flows. 💡

Now it speaks in many tongues, 🌍

To serve all, not just some. 🌐

So let's celebrate this feat, 🥳

With every language, it can greet! 🗣️🎉


Uplevel your code reviews with Entelligence.AI Pro

Entelligence.AI Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, Entelligence.AI Pro is free for open source projects.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description Entelligence.AI

Commits Files that changed from the base of the PR and between 8d93d3e and 3823c6f commits.
Files selected (5)
  • app/lib/pages/home/page.dart (1)
  • app/lib/providers/capture_provider.dart (3)
  • app/lib/providers/speech_profile_provider.dart (1)
  • app/lib/services/sockets.dart (4)
  • app/lib/services/sockets/transcription_connection.dart (2)
Review comments generated (12)
  • Review: 10
  • LGTM: 2

Tips

Chat with Image description Entelligence.AI Bot (@Entelligence.AI)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @Entelligence.AI in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @Entelligence.AI: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines +385 to +391
setRecordingLanguage: (language) {
provider.setRecordingLanguage(language);

// Notify capture provider
if (context.mounted) {
context.read<CaptureProvider>().onRecordProfileSettingChanged();
}
Copy link

Choose a reason for hiding this comment

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

Image description Entelligence.AI

The changes look good, but it's important to note that the context.mounted check is not necessary here. The mounted property in Flutter is used to check if the BuildContext is still in the widget tree, which is useful before calling setState. However, in this case, you're using a provider and not directly setting state, so the check isn't needed.

-                               // Notify capture provider
-                               if (context.mounted) {
-                                 context.read<CaptureProvider>().onRecordProfileSettingChanged();
-                               }
+                               // Notify capture provider
+                               context.read<CaptureProvider>().onRecordProfileSettingChanged();

Comment on lines +138 to +141
String language = SharedPreferencesUtil().recordingsLanguage;
_socket = await ServiceManager.instance()
.socket
.memory(codec: codec, sampleRate: sampleRate, language: language, force: force);
Copy link

Choose a reason for hiding this comment

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

Image description Entelligence.AI

The SharedPreferencesUtil().recordingsLanguage is directly accessed without any null check. If the shared preferences instance or the recordingsLanguage property is null, this will cause a null pointer exception. Consider adding a null check before using it.

- String language = SharedPreferencesUtil().recordingsLanguage;
+ String? language = SharedPreferencesUtil()?.recordingsLanguage ?? 'default_language';

@@ -184,7 +187,7 @@ class CaptureProvider extends ChangeNotifier
debugPrint('resetState');
_cleanupCurrentState();
await _recheckCodecChange();
await _ensureSocketConnection(force: true);
await _ensureSocketConnection();
Copy link

Choose a reason for hiding this comment

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

Image description Entelligence.AI

The _ensureSocketConnection() method was previously called with a force: true parameter. This has been removed in the new code. If the force parameter is necessary for certain scenarios, its removal could lead to issues. Please ensure that this change is intentional and won't affect the functionality.

Comment on lines +245 to +249
Future<void> _ensureSocketConnection() async {
var codec = SharedPreferencesUtil().deviceCodec;
if (codec != _socket?.codec || _socket?.state != SocketServiceState.connected) {
await _initiateWebsocket(force: force);
var language = SharedPreferencesUtil().recordingsLanguage;
if (language != _socket?.language || codec != _socket?.codec || _socket?.state != SocketServiceState.connected) {
await _initiateWebsocket(audioCodec: codec, force: true);
Copy link

Choose a reason for hiding this comment

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

Image description Entelligence.AI

Similar to the previous comment, the SharedPreferencesUtil().deviceCodec and SharedPreferencesUtil().recordingsLanguage are directly accessed without any null checks. If the shared preferences instance or the deviceCodec or recordingsLanguage properties are null, this will cause a null pointer exception. Consider adding null checks before using them.

- var codec = SharedPreferencesUtil().deviceCodec;
- var language = SharedPreferencesUtil().recordingsLanguage;
+ var codec = SharedPreferencesUtil()?.deviceCodec ?? 'default_codec';
+ var language = SharedPreferencesUtil()?.recordingsLanguage ?? 'default_language';

Comment on lines 12 to +16
Future<TranscriptSegmentSocketService?> memory(
{required BleAudioCodec codec, required int sampleRate, bool force = false});
{required BleAudioCodec codec, required int sampleRate, String language = defaultLanguage, bool force = false});

Future<TranscriptSegmentSocketService?> speechProfile(
{required BleAudioCodec codec, required int sampleRate, bool force = false});
{required BleAudioCodec codec, required int sampleRate, String language = defaultLanguage, bool force = false});
Copy link

Choose a reason for hiding this comment

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

Image description Entelligence.AI

The memory and speechProfile methods now have a new optional parameter language with a default value of defaultLanguage. This is a good change as it allows the language to be specified when creating socket services. However, please ensure that all calls to these methods are updated to pass the language parameter if needed.

@@ -35,6 +37,7 @@ class SocketServicePool extends ISocketService {
Future<TranscriptSegmentSocketService?> socket({
required BleAudioCodec codec,
required int sampleRate,
required String language,
Copy link

Choose a reason for hiding this comment

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

Image description Entelligence.AI

The socket method now requires a language parameter. This is a good change as it ensures that the language is always specified when creating a socket service. However, please ensure that all calls to this method are updated to pass the language parameter.

@@ -53,7 +56,7 @@ class SocketServicePool extends ISocketService {
// new socket
await _socket?.stop();

_socket = MemoryTranscriptSegmentSocketService.create(sampleRate, codec);
_socket = MemoryTranscriptSegmentSocketService.create(sampleRate, codec, language);
Copy link

Choose a reason for hiding this comment

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

Image description Entelligence.AI

The MemoryTranscriptSegmentSocketService.create method now takes an additional language parameter. This is a good change as it allows the language to be specified when creating a MemoryTranscriptSegmentSocketService. However, please ensure that the create method in the MemoryTranscriptSegmentSocketService class has been updated to accept and handle this new parameter.

Comment on lines +75 to +90
{required BleAudioCodec codec,
required int sampleRate,
String language = defaultLanguage,
bool force = false}) async {
debugPrint("socket memory > $codec $sampleRate $force");
return await socket(codec: codec, sampleRate: sampleRate, force: force);
return await socket(codec: codec, sampleRate: sampleRate, language: language, force: force);
}

@override
Future<TranscriptSegmentSocketService?> speechProfile(
{required BleAudioCodec codec, required int sampleRate, bool force = false}) async {
{required BleAudioCodec codec,
required int sampleRate,
String language = defaultLanguage,
bool force = false}) async {
debugPrint("socket speech profile > $codec $sampleRate $force");
return await socket(codec: codec, sampleRate: sampleRate, force: force);
return await socket(codec: codec, sampleRate: sampleRate, language: language, force: force);
Copy link

Choose a reason for hiding this comment

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

Image description Entelligence.AI

The memory and speechProfile methods now pass the language parameter to the socket method. This is a good change as it ensures that the language is always specified when creating a socket service. However, please ensure that all calls to these methods are updated to pass the language parameter if needed.

Comment on lines +26 to +32
SpeechProfileTranscriptSegmentSocketService.create(super.sampleRate, super.codec, super.language)
: super.create(includeSpeechProfile: false);
}

class MemoryTranscriptSegmentSocketService extends TranscriptSegmentSocketService {
MemoryTranscriptSegmentSocketService.create(super.sampleRate, super.codec) : super.create(includeSpeechProfile: true);
MemoryTranscriptSegmentSocketService.create(super.sampleRate, super.codec, super.language)
: super.create(includeSpeechProfile: true);
Copy link

Choose a reason for hiding this comment

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

Image description Entelligence.AI

The constructors for SpeechProfileTranscriptSegmentSocketService and MemoryTranscriptSegmentSocketService are using super.sampleRate, super.codec, and super.language. However, these properties are not defined in the superclass constructor. Instead, they should be passed as parameters to the constructor of these classes.

-  SpeechProfileTranscriptSegmentSocketService.create(super.sampleRate, super.codec, super.language)
+  SpeechProfileTranscriptSegmentSocketService.create(int sampleRate, BleAudioCodec codec, String language)

-  MemoryTranscriptSegmentSocketService.create(super.sampleRate, super.codec, super.language)
+  MemoryTranscriptSegmentSocketService.create(int sampleRate, BleAudioCodec codec, String language)

Comment on lines +49 to +58
String language;
bool includeSpeechProfile;

TranscriptSegmentSocketService.create(
this.sampleRate,
this.codec, {
this.codec,
this.language, {
this.includeSpeechProfile = false,
}) {
final recordingsLanguage = SharedPreferencesUtil().recordingsLanguage;
var params = '?language=$recordingsLanguage&sample_rate=$sampleRate&codec=$codec&uid=${SharedPreferencesUtil().uid}'
var params = '?language=$language&sample_rate=$sampleRate&codec=$codec&uid=${SharedPreferencesUtil().uid}'
Copy link

Choose a reason for hiding this comment

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

Image description Entelligence.AI

The SharedPreferencesUtil().uid and SharedPreferencesUtil().transcriptionModel are directly used while constructing the URL. This could lead to potential null pointer exceptions if these shared preferences are not set. It would be better to check for null values before using them.

- var params = '?language=$language&sample_rate=$sampleRate&codec=$codec&uid=${SharedPreferencesUtil().uid}'
-        '&include_speech_profile=$includeSpeechProfile&stt_service=${SharedPreferencesUtil().transcriptionModel}';
+ var uid = SharedPreferencesUtil().uid ?? '';
+ var transcriptionModel = SharedPreferencesUtil().transcriptionModel ?? '';
+ var params = '?language=$language&sample_rate=$sampleRate&codec=$codec&uid=$uid'
+        '&include_speech_profile=$includeSpeechProfile&stt_service=$transcriptionModel';

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