Merge branch 'main' into toolbar-testing

pull/1011/head
Gabby Gurdin 2 years ago
commit cd7fbc020a

@ -86,86 +86,81 @@ class PangeaMessageEvent {
//if no audio exists, create it //if no audio exists, create it
//if audio exists, return it //if audio exists, return it
Future<Event?> getAudioGlobal(String langCode) async { Future<Event?> getAudioGlobal(String langCode) async {
try { final String text = representationByLanguage(langCode)?.text ?? body;
final String text = representationByLanguage(langCode)?.text ?? body;
final local = getAudioLocal(langCode, text); final local = getAudioLocal(langCode, text);
if (local != null) return Future.value(local); if (local != null) return Future.value(local);
final TextToSpeechRequest params = TextToSpeechRequest( final TextToSpeechRequest params = TextToSpeechRequest(
text: text, text: text,
langCode: langCode, langCode: langCode,
); );
final TextToSpeechResponse response = final TextToSpeechResponse response =
await MatrixState.pangeaController.textToSpeech.get( await MatrixState.pangeaController.textToSpeech.get(
params, params,
); );
if (response.mediaType != 'audio/ogg') { if (response.mediaType != 'audio/ogg') {
throw Exception('Unexpected media type: ${response.mediaType}'); throw Exception('Unexpected media type: ${response.mediaType}');
} }
final audioBytes = base64.decode(response.audioContent); final audioBytes = base64.decode(response.audioContent);
// if (!TextToSpeechController.isOggFile(audioBytes)) { // if (!TextToSpeechController.isOggFile(audioBytes)) {
// throw Exception("File is not a valid OGG format"); // throw Exception("File is not a valid OGG format");
// } else { // } else {
// debugPrint("File is a valid OGG format"); // debugPrint("File is a valid OGG format");
// } // }
// from text, trim whitespace, remove special characters, and limit to 20 characters // from text, trim whitespace, remove special characters, and limit to 20 characters
// final fileName = // final fileName =
// text.trim().replaceAll(RegExp('[^A-Za-z0-9]'), '').substring(0, 20); // text.trim().replaceAll(RegExp('[^A-Za-z0-9]'), '').substring(0, 20);
final eventIdParam = _event.eventId; final eventIdParam = _event.eventId;
final fileName = "audio_for_${eventIdParam}_$langCode"; final fileName = "audio_for_${eventIdParam}_$langCode";
final file = MatrixAudioFile( final file = MatrixAudioFile(
bytes: audioBytes, bytes: audioBytes,
name: fileName, name: fileName,
mimeType: response.mediaType, mimeType: response.mediaType,
); );
if (file.mimeType != "audio/ogg") { if (file.mimeType != "audio/ogg") {
debugPrint("Unexpected mime type for audio: ${file.mimeType}"); debugPrint("Unexpected mime type for audio: ${file.mimeType}");
// throw Exception("Unexpected mime type: ${file.mimeType}"); // throw Exception("Unexpected mime type: ${file.mimeType}");
} }
// try { // try {
final String? eventId = await room.sendFileEvent( final String? eventId = await room.sendFileEvent(
file, file,
inReplyTo: _event, inReplyTo: _event,
extraContent: { extraContent: {
'info': { 'info': {
...file.info, ...file.info,
'duration': response.durationMillis, 'duration': response.durationMillis,
},
'org.matrix.msc3245.voice': {},
'org.matrix.msc1767.audio': {
'duration': response.durationMillis,
'waveform': response.waveform,
},
ModelKey.transcription: {
ModelKey.text: text,
ModelKey.langCode: langCode,
},
}, },
); 'org.matrix.msc3245.voice': {},
// .timeout( 'org.matrix.msc1767.audio': {
// Durations.long4, 'duration': response.durationMillis,
// onTimeout: () { 'waveform': response.waveform,
// debugPrint("timeout in getAudioGlobal"); },
// return null; ModelKey.transcription: {
// }, ModelKey.text: text,
// ); ModelKey.langCode: langCode,
},
debugPrint("eventId in getAudioGlobal $eventId"); },
return eventId != null ? room.getEventById(eventId) : null; );
} catch (err) { // .timeout(
debugPrint("error in getAudioGlobal"); // Durations.long4,
return null; // onTimeout: () {
} // debugPrint("timeout in getAudioGlobal");
// return null;
// },
// );
debugPrint("eventId in getAudioGlobal $eventId");
return eventId != null ? room.getEventById(eventId) : null;
} }
Event? getAudioLocal(String langCode, String text) { Event? getAudioLocal(String langCode, String text) {

Loading…
Cancel
Save