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

Revert "feat: initialize WhisperKit on app startup (with config flag)" #1813

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions ios/Runner/WhisperKitRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@ public class WhisperKitRunner: NSObject, FlutterStreamHandler {

transcriptionChannel.setMethodCallHandler { (call, result) in
switch call.method {

case "initialize":
if (self.whisperKit == nil) {
if (self.eventSink != nil) {
self.eventSink!(["Initializing model...", ""])
}
}

Task {
if (self.whisperKit == nil) {
self.whisperKit = try? await WhisperKit(model: self.model,
verbose: true,
prewarm: true)
}
}

case "transcribe":
guard let args = call.arguments as? [String: Any] else { return }
let audioFilePath = args["audioFilePath"] as! String
Expand Down
7 changes: 0 additions & 7 deletions lib/database/journal_db/config_flags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ Future<void> initConfigFlags(
status: false,
),
);
await db.insertFlagIfNotExists(
const ConfigFlag(
name: initializeAsrModelOnStartup,
description: 'Initialize WhisperKit ASR model on startup',
status: false,
),
);
await db.insertFlagIfNotExists(
const ConfigFlag(
name: enableMatrixFlag,
Expand Down
1 change: 0 additions & 1 deletion lib/pages/settings/flags_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class FlagsPage extends StatelessWidget {
attemptEmbedding,
enableNotificationsFlag,
autoTranscribeFlag,
initializeAsrModelOnStartup,
recordLocationFlag,
allowInvalidCertFlag,
enableMatrixFlag,
Expand Down
26 changes: 0 additions & 26 deletions lib/services/asr_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@ import 'package:ffmpeg_kit_flutter/return_code.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:lotti/classes/journal_entities.dart';
import 'package:lotti/database/database.dart';
import 'package:lotti/database/logging_db.dart';
import 'package:lotti/database/settings_db.dart';
import 'package:lotti/get_it.dart';
import 'package:lotti/logic/persistence_logic.dart';
import 'package:lotti/utils/audio_utils.dart';
import 'package:lotti/utils/consts.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';

class AsrService {
AsrService() {
_loadSelectedModel();
_initialize();

eventChannel.receiveBroadcastStream().listen(
_onEvent,
onError: _onError,
Expand Down Expand Up @@ -179,28 +175,6 @@ class AsrService {
running = false;
}

Future<void> _initialize() async {
final initializeOnStartup = await getIt<JournalDb>().getConfigFlag(
initializeAsrModelOnStartup,
);

if (!initializeOnStartup) {
return;
}

getIt<LoggingDb>().captureEvent(
'initializing WhisperKit',
domain: 'ASR',
subDomain: 'initialize',
);

try {
unawaited(methodChannel.invokeMethod('initialize'));
} on PlatformException catch (e) {
captureException(e);
}
}

Future<bool> enqueue({required JournalAudio entry}) async {
final isQueueEmpty = queue.isEmpty;
queue.add(entry);
Expand Down
1 change: 0 additions & 1 deletion lib/utils/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const allowInvalidCertFlag = 'allow_invalid_cert';
const enableSyncFlag = 'enable_sync';
const recordLocationFlag = 'record_location';
const autoTranscribeFlag = 'auto_transcribe';
const initializeAsrModelOnStartup = 'initialize_asr_model_on_startup';
const enableMatrixFlag = 'enable_matrix';
const resendAttachments = 'resend_attachments';
const attemptEmbedding = 'attempt_embedding';
26 changes: 5 additions & 21 deletions macos/Runner/WhisperKitRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,26 @@ public class WhisperKitRunner: NSObject, FlutterStreamHandler {

transcriptionChannel.setMethodCallHandler { (call, result) in
switch call.method {

case "initialize":
if (self.whisperKit == nil) {
if (self.eventSink != nil) {
self.eventSink!(["Initializing model...", ""])
}
}

Task {
if (self.whisperKit == nil) {
self.whisperKit = try? await WhisperKit(model: self.model,
verbose: true,
prewarm: true)
}
}

case "transcribe":
guard let args = call.arguments as? [String: Any] else { return }
let audioFilePath = args["audioFilePath"] as! String
let language = args["language"] as! String
let detectLanguage = language.isEmpty

if (self.whisperKit == nil) {
if (self.eventSink != nil) {
self.eventSink!(["Initializing model...", ""])
}
}



Task {
if (self.whisperKit == nil) {
self.whisperKit = try? await WhisperKit(model: self.model,
verbose: true,
prewarm: true)
}

let transcription = try? await self.whisperKit!.transcribe(
audioPath: audioFilePath,
decodeOptions: DecodingOptions(
Expand All @@ -70,13 +55,12 @@ public class WhisperKitRunner: NSObject, FlutterStreamHandler {
),
callback: self.sendTranscriptionProgressEvent
)

let text : String? = transcription?.first?.text
let detectedLanguage = transcription?.first?.language
let data = [detectedLanguage, self.model, text]
result(data)
}

default:
result(FlutterMethodNotImplemented)
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: lotti
description: Achieve your goals and keep your data private with Lotti.
publish_to: 'none'
version: 0.9.505+2662
version: 0.9.506+2663

msix_config:
display_name: LottiApp
Expand Down
5 changes: 0 additions & 5 deletions test/database/database_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ final expectedFlags = <ConfigFlag>{
description: 'Automatically transcribe audio',
status: false,
),
const ConfigFlag(
name: initializeAsrModelOnStartup,
description: 'Initialize WhisperKit ASR model on startup',
status: false,
),
const ConfigFlag(
name: recordLocationFlag,
description: 'Record geolocation?',
Expand Down
Loading