aboutsummaryrefslogtreecommitdiffstats
path: root/lib/widgets/stt_model_choice.dart
diff options
context:
space:
mode:
Diffstat (limited to 'lib/widgets/stt_model_choice.dart')
-rw-r--r--lib/widgets/stt_model_choice.dart148
1 files changed, 148 insertions, 0 deletions
diff --git a/lib/widgets/stt_model_choice.dart b/lib/widgets/stt_model_choice.dart
new file mode 100644
index 0000000..fc0e099
--- /dev/null
+++ b/lib/widgets/stt_model_choice.dart
@@ -0,0 +1,148 @@
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+import '../models/app_state.dart';
+
+enum STTModel{
+ vosk,
+ whisper
+}
+
+class STTModelChoice extends StatefulWidget {
+ final Function(STTModel) onModelChanged;
+ final String theme;
+
+ const STTModelChoice({
+ Key? key,
+ required this.onModelChanged,
+ required this.theme
+ }) : super(key: key);
+
+ @override
+ State<STTModelChoice> createState() => _STTModelChoiceState();
+}
+
+class _STTModelChoiceState extends State<STTModelChoice> {
+ late STTModel _selectedModel;
+ late String _theme;
+
+ @override
+ void initState() {
+ super.initState();
+ final appState = context.read<AppState>();
+ _selectedModel = appState.sttFramework == "vosk" ? STTModel.vosk : STTModel.whisper;
+ _theme = widget.theme;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: <Widget>[
+ InkWell(
+ onTap: () => _onModelChanged(STTModel.vosk),
+ borderRadius: BorderRadius.only(
+ topLeft: Radius.circular(20.0),
+ bottomLeft: Radius.circular(20.0),
+ ),
+ child: Container(
+ padding: EdgeInsets.symmetric(horizontal: 17.5, vertical: 5.0),
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.only(
+ topLeft: Radius.circular(20.0),
+ bottomLeft: Radius.circular(20.0),
+ ),
+ color: _selectedModel == STTModel.vosk
+ ? Colors.green
+ : _theme == "dark" || _theme == "textured-dark"
+ ? Colors.black
+ : Colors.white,
+ border: Border.all(
+ color: Colors.transparent,
+ ),
+ ),
+ child: Row(
+ children: [
+ Icon(
+ _selectedModel == STTModel.vosk
+ ? Icons.check
+ : Icons.transcribe_sharp,
+ color: _selectedModel == STTModel.vosk
+ ? Colors.white
+ : Colors.green,
+ ),
+ SizedBox(width: 8),
+ Text(
+ 'Vosk',
+ style: TextStyle(
+ fontWeight: FontWeight.bold,
+ fontSize: 17,
+ color: _selectedModel == STTModel.vosk
+ ? Colors.white
+ : Colors.green,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ InkWell(
+ onTap: () => _onModelChanged(STTModel.whisper),
+ borderRadius: BorderRadius.only(
+ topRight: Radius.circular(20.0),
+ bottomRight: Radius.circular(20.0),
+ ),
+ child: Container(
+ padding: EdgeInsets.symmetric(horizontal: 17.5, vertical: 5.0),
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.only(
+ topRight: Radius.circular(20.0),
+ bottomRight: Radius.circular(20.0),
+ ),
+ color: _selectedModel == STTModel.whisper
+ ? Colors.green
+ : _theme == "dark" || _theme == "textured-dark"
+ ? Colors.black
+ : Colors.white,
+ border: Border.all(
+ color: Colors.transparent,
+ ),
+ ),
+ child: Row(
+ children: [
+ Icon(
+ _selectedModel == STTModel.whisper
+ ? Icons.check
+ : Icons.transcribe_sharp,
+ color: _selectedModel == STTModel.whisper
+ ? Colors.white
+ : Colors.green,
+ ),
+ SizedBox(width: 8),
+ Text(
+ 'Whisper',
+ style: TextStyle(
+ fontWeight: FontWeight.bold,
+ fontSize: 17,
+ color: _selectedModel == STTModel.whisper
+ ? Colors.white
+ : Colors.green,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ],
+ );
+ }
+
+ void _onModelChanged(STTModel newModel) {
+ setState(() {
+ _selectedModel = newModel;
+ });
+
+ // Call the callback function to notify the engine change
+ widget.onModelChanged(newModel);
+ }
+} \ No newline at end of file