setupUI function
Future<void>
setupUI(
{ - String? openAiKey,
- TTSModel tts()?,
})
Implementation
Future<void> setupUI({
String? openAiKey,
TTSModel Function()? tts,
}) async {
WidgetsFlutterBinding.ensureInitialized();
if (Platform.isIOS) {
TerminalLogger.printer = TerminalPrinter.developerLog;
//TerminalLogger.disableColorfulOutput = true;
}
var sp = await SharedPreferences.getInstance();
GetIt.I.registerSingleton(sp);
Directory appDocDir = await getApplicationDocumentsDirectory();
String dbPath = '${appDocDir.path}${Platform.pathSeparator}local_storage.db';
Database db = sqlite3.open(dbPath);
var localStorageRepository = LocalStorageRepository(sp, db);
await localStorageRepository.prepare();
GetIt.I.registerSingleton(localStorageRepository);
setupFactories(
localStorage: () => LocalStorageRepository(sp, db),
recorder: () => VitAudioRecorder(),
tts: tts,
simplePlayerFactory: (file) {
return VitAudioPlayer(
audioPath: file.path,
randomizeVolumeStream: true,
).getPlayer();
},
);
var directory = await getApplicationDocumentsDirectory();
VitGptConfiguration.internalFilesDirectory = directory;
VitGptConfiguration.useHighQualityTts = false;
VitGptConfiguration.ttsFormat = AudioFormat.mp3;
// Setting the API token to the http client.
if (openAiKey != null) {
await updateApiToken(openAiKey);
}
}