aboutsummaryrefslogtreecommitdiffstats
path: root/lib/widgets/stt_model_choice.dart
blob: fc0e0996c32eacf2805b5ac0d63baf070edadf55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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);
  }
}