fix to listening with already made audio
This commit is contained in:
parent
b865e629a7
commit
23055e65d1
8 changed files with 99 additions and 76 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import 'package:collection/collection.dart';
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/config/environment.dart';
|
||||
import 'package:fluffychat/pangea/controllers/language_list_controller.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:fluffychat/pangea/utils/firebase_analytics.dart';
|
||||
|
|
@ -22,7 +21,13 @@ void main() async {
|
|||
Logs().i('Welcome to ${AppConfig.applicationName} <3');
|
||||
|
||||
// #Pangea
|
||||
await dotenv.load(fileName: Environment.fileName);
|
||||
try {
|
||||
await dotenv.load(fileName: ".env");
|
||||
} catch (e) {
|
||||
Logs().e('Failed to load .env file', e);
|
||||
}
|
||||
// await dotenv.load(fileName: ".env");
|
||||
// await dotenv.load(fileName: Environment.fileName);
|
||||
|
||||
await Future.wait([
|
||||
ErrorHandler.initialize(),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import 'dart:async';
|
|||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fluffychat/pangea/controllers/text_to_speech_controller.dart';
|
||||
import 'package:fluffychat/utils/error_reporter.dart';
|
||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
|
@ -147,11 +146,12 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
mimeType: "audio/ogg",
|
||||
);
|
||||
debugPrint("audioType is $mimeType");
|
||||
if (!TextToSpeechController.isOggFile(matrixFile!.bytes)) {
|
||||
debugger(when: kDebugMode);
|
||||
} else {
|
||||
debugPrint("still an ogg file!");
|
||||
}
|
||||
// TODO - figure out why it's a wav at this point
|
||||
// if (!TextToSpeechController.isOggFile(matrixFile!.bytes)) {
|
||||
// debugger(when: kDebugMode);
|
||||
// } else {
|
||||
// debugPrint("still an ogg file!");
|
||||
// }
|
||||
try {
|
||||
// Pangea#
|
||||
await audioPlayer.setAudioSource(MatrixFileAudioSource(matrixFile!));
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:fluffychat/pangea/controllers/base_controller.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/message_data_models.dart';
|
||||
import 'package:fluffychat/pangea/repo/tokens_repo.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
|
@ -137,7 +134,7 @@ class MessageDataController extends BaseController {
|
|||
type: PangeaEventTypes.representation,
|
||||
);
|
||||
|
||||
debugger(when: kDebugMode && repEvent == null);
|
||||
// debugger(when: kDebugMode && repEvent == null);
|
||||
|
||||
return repEvent;
|
||||
} catch (err, stack) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
||||
|
|
@ -11,7 +10,6 @@ import 'package:fluffychat/pangea/models/class_model.dart';
|
|||
import 'package:fluffychat/pangea/models/message_data_models.dart';
|
||||
import 'package:fluffychat/pangea/models/pangea_representation_event.dart';
|
||||
import 'package:fluffychat/pangea/utils/bot_name.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
|
|
@ -88,51 +86,53 @@ class PangeaMessageEvent {
|
|||
//if no audio exists, create it
|
||||
//if audio exists, return it
|
||||
Future<Event?> getAudioGlobal(String langCode) async {
|
||||
// try {
|
||||
final String text = representationByLanguage(langCode)?.text ?? body;
|
||||
|
||||
final local = getAudioLocal(langCode, text);
|
||||
|
||||
if (local != null) return Future.value(local);
|
||||
|
||||
final TextToSpeechRequest params = TextToSpeechRequest(
|
||||
text: text,
|
||||
langCode: langCode,
|
||||
);
|
||||
|
||||
final TextToSpeechResponse response =
|
||||
await MatrixState.pangeaController.textToSpeech.get(
|
||||
params,
|
||||
);
|
||||
|
||||
if (response.mediaType != 'audio/ogg') {
|
||||
throw Exception('Unexpected media type: ${response.mediaType}');
|
||||
}
|
||||
|
||||
final audioBytes = base64.decode(response.audioContent);
|
||||
|
||||
if (!TextToSpeechController.isOggFile(audioBytes)) {
|
||||
throw Exception("File is not a valid OGG format");
|
||||
} else {
|
||||
debugPrint("File is a valid OGG format");
|
||||
}
|
||||
|
||||
// from text, trim whitespace, remove special characters, and limit to 20 characters
|
||||
// final fileName =
|
||||
// text.trim().replaceAll(RegExp('[^A-Za-z0-9]'), '').substring(0, 20);
|
||||
final fileName = "audio_for_${eventId}_$langCode";
|
||||
|
||||
final file = MatrixAudioFile(
|
||||
bytes: audioBytes,
|
||||
name: fileName,
|
||||
mimeType: response.mediaType,
|
||||
);
|
||||
|
||||
if (file.mimeType != "audio/ogg") {
|
||||
throw Exception("Unexpected mime type: ${file.mimeType}");
|
||||
}
|
||||
|
||||
try {
|
||||
final String text = representationByLanguage(langCode)?.text ?? body;
|
||||
|
||||
final local = getAudioLocal(langCode, text);
|
||||
|
||||
if (local != null) return Future.value(local);
|
||||
|
||||
final TextToSpeechRequest params = TextToSpeechRequest(
|
||||
text: text,
|
||||
langCode: langCode,
|
||||
);
|
||||
|
||||
final TextToSpeechResponse response =
|
||||
await MatrixState.pangeaController.textToSpeech.get(
|
||||
params,
|
||||
);
|
||||
|
||||
if (response.mediaType != 'audio/ogg') {
|
||||
throw Exception('Unexpected media type: ${response.mediaType}');
|
||||
}
|
||||
|
||||
final audioBytes = base64.decode(response.audioContent);
|
||||
|
||||
// if (!TextToSpeechController.isOggFile(audioBytes)) {
|
||||
// throw Exception("File is not a valid OGG format");
|
||||
// } else {
|
||||
// debugPrint("File is a valid OGG format");
|
||||
// }
|
||||
|
||||
// from text, trim whitespace, remove special characters, and limit to 20 characters
|
||||
// final fileName =
|
||||
// text.trim().replaceAll(RegExp('[^A-Za-z0-9]'), '').substring(0, 20);
|
||||
final eventIdParam = _event.eventId;
|
||||
final fileName = "audio_for_${eventIdParam}_$langCode";
|
||||
|
||||
final file = MatrixAudioFile(
|
||||
bytes: audioBytes,
|
||||
name: fileName,
|
||||
mimeType: response.mediaType,
|
||||
);
|
||||
|
||||
if (file.mimeType != "audio/ogg") {
|
||||
debugPrint("Unexpected mime type for audio: ${file.mimeType}");
|
||||
// throw Exception("Unexpected mime type: ${file.mimeType}");
|
||||
}
|
||||
|
||||
// try {
|
||||
final String? eventId = await room.sendFileEvent(
|
||||
file,
|
||||
inReplyTo: _event,
|
||||
|
|
@ -164,7 +164,6 @@ class PangeaMessageEvent {
|
|||
return eventId != null ? room.getEventById(eventId) : null;
|
||||
} catch (err) {
|
||||
debugPrint("error in getAudioGlobal");
|
||||
debugger(when: kDebugMode);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ class ErrorHandler {
|
|||
if ((e ?? m) != null) debugPrint("error to string: ${e?.toString() ?? m}");
|
||||
if (data != null) {
|
||||
Sentry.addBreadcrumb(Breadcrumb.fromJson(data));
|
||||
debugPrint(data.toString());
|
||||
}
|
||||
FlutterError.reportError(
|
||||
FlutterErrorDetails(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pages/chat/events/audio_player.dart';
|
||||
import 'package:fluffychat/pangea/models/pangea_message_event.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
|
@ -29,12 +30,22 @@ class MessageAudioCardState extends State<MessageAudioCard> {
|
|||
.then((Event? event) {
|
||||
localAudioEvent = event;
|
||||
}).catchError((e) {
|
||||
debugPrint(StackTrace.current.toString());
|
||||
if (!mounted) return null;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(L10n.of(context)!.errorGettingAudio),
|
||||
),
|
||||
);
|
||||
ErrorHandler.logError(
|
||||
e: Exception(),
|
||||
s: StackTrace.current,
|
||||
m: 'something wrong getting audio in MessageAudioCardState',
|
||||
data: {
|
||||
'widget.messageEvent.messageDisplayLangCode':
|
||||
widget.messageEvent.messageDisplayLangCode,
|
||||
},
|
||||
);
|
||||
return null;
|
||||
}).whenComplete(() {
|
||||
if (mounted) setState(() => _isLoading = false);
|
||||
|
|
|
|||
|
|
@ -45,10 +45,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: collection
|
||||
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
|
||||
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.17.1"
|
||||
version: "1.18.0"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -132,26 +132,26 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: matcher
|
||||
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
|
||||
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.12.15"
|
||||
version: "0.12.16"
|
||||
material_color_utilities:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: material_color_utilities
|
||||
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
|
||||
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.2.0"
|
||||
version: "0.5.0"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
|
||||
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
version: "1.10.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -185,26 +185,26 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: source_span
|
||||
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
|
||||
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
version: "1.10.0"
|
||||
stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stack_trace
|
||||
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
|
||||
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.11.0"
|
||||
version: "1.11.1"
|
||||
stream_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stream_channel
|
||||
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
|
||||
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
version: "2.1.2"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -225,10 +225,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
|
||||
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.5.1"
|
||||
version: "0.6.1"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -237,6 +237,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web
|
||||
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.0"
|
||||
sdks:
|
||||
dart: ">=3.0.0-0 <4.0.0"
|
||||
dart: ">=3.2.0-194.0.dev <4.0.0"
|
||||
flutter: ">=1.20.0"
|
||||
|
|
|
|||
|
|
@ -146,6 +146,8 @@ flutter:
|
|||
assets:
|
||||
- assets/
|
||||
# #Pangea
|
||||
- .env
|
||||
- assets/.env
|
||||
- assets/pangea/
|
||||
- assets/pangea/bot_faces/
|
||||
# Pangea#
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue