always show transcription
This commit is contained in:
parent
f7d8a09845
commit
99fd9f9cb0
3 changed files with 68 additions and 57 deletions
|
|
@ -94,8 +94,8 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
|
|||
bool showTranslation = false;
|
||||
String? translationText;
|
||||
|
||||
bool showTranscription = false;
|
||||
String? transcriptText;
|
||||
String? transcriptionText;
|
||||
String? transcriptionError;
|
||||
|
||||
double maxWidth = AppConfig.toolbarMinWidth;
|
||||
|
||||
|
|
@ -586,14 +586,20 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
|
|||
}
|
||||
}
|
||||
|
||||
void setShowTranscription(bool show, String? transcription) {
|
||||
if (showTranscription == show) return;
|
||||
if (show && transcription == null) return;
|
||||
|
||||
void setTranscriptionText(String transcription) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
showTranscription = show;
|
||||
transcriptText = show ? transcription : null;
|
||||
transcriptionError = null;
|
||||
transcriptionText = transcription;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void setTranscriptionError(String error) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
transcriptionText = null;
|
||||
transcriptionError = error;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pages/chat/chat.dart';
|
||||
import 'package:fluffychat/pages/chat/events/message_content.dart';
|
||||
import 'package:fluffychat/pages/chat/events/reply_content.dart';
|
||||
|
|
@ -136,8 +137,7 @@ class OverlayMessage extends StatelessWidget {
|
|||
final showTranslation = overlayController.showTranslation &&
|
||||
overlayController.translationText != null;
|
||||
|
||||
final showTranscription = overlayController.showTranscription &&
|
||||
overlayController.transcriptText != null;
|
||||
final showTranscription = pangeaMessageEvent?.isAudioMessage == true;
|
||||
|
||||
final content = Container(
|
||||
decoration: BoxDecoration(
|
||||
|
|
@ -278,17 +278,37 @@ class OverlayMessage extends StatelessWidget {
|
|||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: SingleChildScrollView(
|
||||
child: Text(
|
||||
overlayController.transcriptText!,
|
||||
style: AppConfig.messageTextStyle(
|
||||
event,
|
||||
textColor,
|
||||
).copyWith(
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: overlayController.transcriptionError != null
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
L10n.of(context).oopsSomethingWentWrong,
|
||||
style: AppConfig.messageTextStyle(
|
||||
event,
|
||||
textColor,
|
||||
).copyWith(fontStyle: FontStyle.italic),
|
||||
),
|
||||
],
|
||||
)
|
||||
: overlayController.transcriptionText != null
|
||||
? SingleChildScrollView(
|
||||
child: Text(
|
||||
overlayController.transcriptionText!,
|
||||
style: AppConfig.messageTextStyle(
|
||||
event,
|
||||
textColor,
|
||||
).copyWith(
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
)
|
||||
: const LinearProgressIndicator(),
|
||||
),
|
||||
),
|
||||
sizeAnimation != null
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ enum SelectMode {
|
|||
audio(Icons.volume_up),
|
||||
translate(Icons.translate),
|
||||
practice(Symbols.fitness_center),
|
||||
transcription(Icons.translate);
|
||||
speechTranslation(Icons.translate);
|
||||
|
||||
final IconData icon;
|
||||
const SelectMode(this.icon);
|
||||
|
|
@ -41,7 +41,7 @@ enum SelectMode {
|
|||
return l10n.translationTooltip;
|
||||
case SelectMode.practice:
|
||||
return l10n.practice;
|
||||
case SelectMode.transcription:
|
||||
case SelectMode.speechTranslation:
|
||||
return l10n.speechToTextTooltip;
|
||||
}
|
||||
}
|
||||
|
|
@ -72,7 +72,7 @@ class SelectModeButtonsState extends State<SelectModeButtons> {
|
|||
];
|
||||
|
||||
static List<SelectMode> get audioModes => [
|
||||
SelectMode.transcription,
|
||||
SelectMode.speechTranslation,
|
||||
SelectMode.practice,
|
||||
];
|
||||
|
||||
|
|
@ -91,9 +91,7 @@ class SelectModeButtonsState extends State<SelectModeButtons> {
|
|||
PangeaRepresentation? _repEvent;
|
||||
String? _translationError;
|
||||
|
||||
bool _isLoadingTranscription = false;
|
||||
SpeechToTextModel? _speechToTextResponse;
|
||||
String? _transcriptionError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
|
@ -113,6 +111,10 @@ class SelectModeButtonsState extends State<SelectModeButtons> {
|
|||
);
|
||||
}
|
||||
});
|
||||
|
||||
if (messageEvent?.isAudioMessage == true) {
|
||||
_loadTranscription();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -135,7 +137,6 @@ class SelectModeButtonsState extends State<SelectModeButtons> {
|
|||
setState(() {
|
||||
_audioError = null;
|
||||
_translationError = null;
|
||||
_transcriptionError = null;
|
||||
});
|
||||
|
||||
widget.overlayController.updateSelectedSpan(null);
|
||||
|
|
@ -143,10 +144,6 @@ class SelectModeButtonsState extends State<SelectModeButtons> {
|
|||
if (_selectedMode == SelectMode.translate) {
|
||||
widget.overlayController.setShowTranslation(false, null);
|
||||
}
|
||||
|
||||
if (_selectedMode == SelectMode.transcription) {
|
||||
widget.overlayController.setShowTranscription(false, null);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _updateMode(SelectMode? mode) async {
|
||||
|
|
@ -181,20 +178,6 @@ class SelectModeButtonsState extends State<SelectModeButtons> {
|
|||
|
||||
if (_selectedMode == SelectMode.translate) {
|
||||
await _loadTranslation();
|
||||
if (_repEvent == null) return;
|
||||
widget.overlayController.setShowTranslation(
|
||||
true,
|
||||
_repEvent!.text,
|
||||
);
|
||||
}
|
||||
|
||||
if (_selectedMode == SelectMode.transcription) {
|
||||
await _loadTranscription();
|
||||
if (_speechToTextResponse == null) return;
|
||||
widget.overlayController.setShowTranscription(
|
||||
true,
|
||||
_speechToTextResponse!.transcript.text,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -312,6 +295,14 @@ class SelectModeButtonsState extends State<SelectModeButtons> {
|
|||
|
||||
try {
|
||||
await _fetchRepresentation();
|
||||
if (_repEvent == null) {
|
||||
throw "No representation found for the selected language.";
|
||||
}
|
||||
|
||||
widget.overlayController.setShowTranslation(
|
||||
true,
|
||||
_repEvent!.text,
|
||||
);
|
||||
} catch (err) {
|
||||
_translationError = err.toString();
|
||||
ErrorHandler.logError(
|
||||
|
|
@ -326,22 +317,20 @@ class SelectModeButtonsState extends State<SelectModeButtons> {
|
|||
}
|
||||
|
||||
Future<void> _loadTranscription() async {
|
||||
if (!mounted) return;
|
||||
setState(() => _isLoadingTranscription = true);
|
||||
|
||||
try {
|
||||
await _fetchTranscription();
|
||||
widget.overlayController.setTranscriptionText(
|
||||
_speechToTextResponse!.transcript.text,
|
||||
);
|
||||
} catch (err) {
|
||||
_transcriptionError = err.toString();
|
||||
widget.overlayController.setTranscriptionError(
|
||||
err.toString(),
|
||||
);
|
||||
ErrorHandler.logError(
|
||||
e: err,
|
||||
data: {},
|
||||
);
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() => _isLoadingTranscription = false);
|
||||
}
|
||||
}
|
||||
|
||||
bool get _isError {
|
||||
|
|
@ -350,8 +339,6 @@ class SelectModeButtonsState extends State<SelectModeButtons> {
|
|||
return _audioError != null;
|
||||
case SelectMode.translate:
|
||||
return _translationError != null;
|
||||
case SelectMode.transcription:
|
||||
return _transcriptionError != null;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
@ -363,8 +350,6 @@ class SelectModeButtonsState extends State<SelectModeButtons> {
|
|||
return _isLoadingAudio;
|
||||
case SelectMode.translate:
|
||||
return _isLoadingTranslation;
|
||||
case SelectMode.transcription:
|
||||
return _isLoadingTranscription;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue