feat: enhance text-to-speech functionality with markdown support
- Integrated markdown conversion in TextToSpeechController to clean text before speech synthesis, ensuring only valid content is spoken. - Updated VoiceCallService to utilize markdown conversion for responses, improving the clarity of spoken content. - Enhanced VoiceCallPage to display cleaned text from markdown, providing a better user experience during voice interactions.
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../core/utils/markdown_to_text.dart';
|
||||
import '../services/text_to_speech_service.dart';
|
||||
|
||||
enum TtsPlaybackStatus { idle, initializing, loading, speaking, paused, error }
|
||||
@@ -161,7 +162,21 @@ class TextToSpeechController extends Notifier<TextToSpeechState> {
|
||||
);
|
||||
|
||||
try {
|
||||
await _service.speak(text);
|
||||
// Convert markdown to clean text for TTS
|
||||
final cleanText = MarkdownToText.convert(text);
|
||||
if (cleanText.isEmpty) {
|
||||
// No speakable content
|
||||
if (!ref.mounted) {
|
||||
return;
|
||||
}
|
||||
state = state.copyWith(
|
||||
status: TtsPlaybackStatus.idle,
|
||||
clearActiveMessageId: true,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await _service.speak(cleanText);
|
||||
if (!ref.mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user