3385 speaker button switches back from pause button too quickly when clicked (#3415)
* fix: took out TextToSpeech use so windows uses FlutterTts instead To fix glitchy audio/pause icon on windows * chore: remove unused package, formatting --------- Co-authored-by: ggurdin <ggurdin@gmail.com>
This commit is contained in:
parent
bcd349a6c3
commit
7934fc8b15
4 changed files with 6 additions and 64 deletions
|
|
@ -10,7 +10,6 @@ import 'package:flutter_tts/flutter_tts.dart' as flutter_tts;
|
|||
import 'package:just_audio/just_audio.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:text_to_speech/text_to_speech.dart';
|
||||
|
||||
import 'package:fluffychat/pages/chat/chat.dart';
|
||||
import 'package:fluffychat/pages/chat/events/audio_player.dart';
|
||||
|
|
@ -20,7 +19,6 @@ import 'package:fluffychat/pangea/instructions/instructions_enum.dart';
|
|||
import 'package:fluffychat/pangea/instructions/instructions_show_popup.dart';
|
||||
import 'package:fluffychat/pangea/learning_settings/constants/language_constants.dart';
|
||||
import 'package:fluffychat/pangea/toolbar/controllers/text_to_speech_controller.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
class TtsController {
|
||||
|
|
@ -31,16 +29,11 @@ class TtsController {
|
|||
static List<String> _availableLangCodes = [];
|
||||
|
||||
static final flutter_tts.FlutterTts _tts = flutter_tts.FlutterTts();
|
||||
static final TextToSpeech _alternativeTTS = TextToSpeech();
|
||||
static final StreamController<bool> loadingChoreoStream =
|
||||
StreamController<bool>.broadcast();
|
||||
|
||||
static AudioPlayer? audioPlayer;
|
||||
|
||||
static bool get _useAlternativeTTS {
|
||||
return PlatformInfos.isWindows;
|
||||
}
|
||||
|
||||
static Future<void> _onError(dynamic message) async {
|
||||
if (message != 'canceled' && message != 'interrupted') {
|
||||
ErrorHandler.logError(
|
||||
|
|
@ -54,12 +47,8 @@ class TtsController {
|
|||
|
||||
static Future<void> setAvailableLanguages() async {
|
||||
try {
|
||||
if (_useAlternativeTTS) {
|
||||
await _setAvailableAltLanguages();
|
||||
} else {
|
||||
await _tts.awaitSpeakCompletion(true);
|
||||
await _setAvailableBaseLanguages();
|
||||
}
|
||||
await _tts.awaitSpeakCompletion(true);
|
||||
await _setAvailableBaseLanguages();
|
||||
} catch (e, s) {
|
||||
debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(
|
||||
|
|
@ -84,11 +73,6 @@ class TtsController {
|
|||
.toList();
|
||||
}
|
||||
|
||||
static Future<void> _setAvailableAltLanguages() async {
|
||||
final languages = await _alternativeTTS.getLanguages();
|
||||
_availableLangCodes = languages.toSet().toList();
|
||||
}
|
||||
|
||||
static Future<void> _setSpeakingLanguage(String langCode) async {
|
||||
String? selectedLangCode;
|
||||
final langCodeShort = langCode.split("-").first;
|
||||
|
|
@ -101,9 +85,7 @@ class TtsController {
|
|||
}
|
||||
|
||||
if (selectedLangCode != null) {
|
||||
await (_useAlternativeTTS
|
||||
? _alternativeTTS.setLanguage(selectedLangCode)
|
||||
: _tts.setLanguage(selectedLangCode));
|
||||
await (_tts.setLanguage(selectedLangCode));
|
||||
} else {
|
||||
final jsonData = {
|
||||
'langCode': langCode,
|
||||
|
|
@ -120,11 +102,10 @@ class TtsController {
|
|||
try {
|
||||
// return type is dynamic but apparent its supposed to be 1
|
||||
// https://pub.dev/packages/flutter_tts
|
||||
final result =
|
||||
await (_useAlternativeTTS ? _alternativeTTS.stop() : _tts.stop());
|
||||
final result = await (_tts.stop());
|
||||
audioPlayer?.stop();
|
||||
|
||||
if (!_useAlternativeTTS && result != 1) {
|
||||
if (result != 1) {
|
||||
ErrorHandler.logError(
|
||||
m: 'Unexpected result from tts.stop',
|
||||
data: {
|
||||
|
|
@ -232,9 +213,7 @@ class TtsController {
|
|||
|
||||
Logs().i('Speaking: $text, langCode: $langCode');
|
||||
final result = await Future(
|
||||
() => (_useAlternativeTTS
|
||||
? _alternativeTTS.speak(text)
|
||||
: _tts.speak(text)),
|
||||
() => (_tts.speak(text)),
|
||||
// .timeout(
|
||||
// const Duration(seconds: 5),
|
||||
// // onTimeout: () {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ import share_plus
|
|||
import shared_preferences_foundation
|
||||
import sqflite_darwin
|
||||
import sqlcipher_flutter_libs
|
||||
import text_to_speech_macos
|
||||
import url_launcher_macos
|
||||
import video_compress
|
||||
import video_player_avfoundation
|
||||
|
|
@ -79,7 +78,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
|||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
|
||||
Sqlite3FlutterLibsPlugin.register(with: registry.registrar(forPlugin: "Sqlite3FlutterLibsPlugin"))
|
||||
TextToSpeechMacOsPlugin.register(with: registry.registrar(forPlugin: "TextToSpeechMacOsPlugin"))
|
||||
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
|
||||
VideoCompressPlugin.register(with: registry.registrar(forPlugin: "VideoCompressPlugin"))
|
||||
FVPVideoPlayerPlugin.register(with: registry.registrar(forPlugin: "FVPVideoPlayerPlugin"))
|
||||
|
|
|
|||
33
pubspec.lock
33
pubspec.lock
|
|
@ -2497,39 +2497,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.8"
|
||||
text_to_speech:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: HEAD
|
||||
resolved-ref: "23c2405aad7fc2408c090c4c98721fd1025fbadf"
|
||||
url: "https://github.com/pangeachat/text_to_speech.git"
|
||||
source: git
|
||||
version: "0.2.3"
|
||||
text_to_speech_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: text_to_speech_macos
|
||||
sha256: "11d1b7d4eff579743b04d371e86d17bebd599f7d998b9fa4cf07a5821cda3b6d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.1"
|
||||
text_to_speech_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: text_to_speech_platform_interface
|
||||
sha256: "9d637f0ae36e296f42a0e555bd65ba4c64a28a7c26a2752fdae62f6d78b6c2d0"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.3"
|
||||
text_to_speech_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: text_to_speech_web
|
||||
sha256: "47d006c0a377c9eb3f6bcca4d92b3ece2c67f5eb31b9416727cc81b92c36d6d1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.2"
|
||||
timezone:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -133,8 +133,6 @@ dependencies:
|
|||
sentry_flutter: ^8.13.2
|
||||
shimmer: ^3.0.0
|
||||
rive: 0.11.11
|
||||
text_to_speech:
|
||||
git: https://github.com/pangeachat/text_to_speech.git
|
||||
flutter_tts: ^4.2.0
|
||||
animated_flip_counter: ^0.3.4
|
||||
# Pangea#
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue