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 audio exists, return it
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(
text: text,
langCode: langCode,
);
final TextToSpeechRequest params = TextToSpeechRequest(
text: text,
langCode: langCode,
);
final TextToSpeechResponse response =
await MatrixState.pangeaController.textToSpeech.get(
params,
);
final TextToSpeechResponse response =
await MatrixState.pangeaController.textToSpeech.get(
params,
);
if (response.mediaType != 'audio/ogg') {
throw Exception('Unexpected media type: ${response.mediaType}');
}
if (response.mediaType != 'audio/ogg') {
throw Exception('Unexpected media type: ${response.mediaType}');
}
final audioBytes = base64.decode(response.audioContent);
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");
// }
// 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";
// 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,
);
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}");
}
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,
extraContent: {
'info': {
...file.info,
'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,
},
// try {
final String? eventId = await room.sendFileEvent(
file,
inReplyTo: _event,
extraContent: {
'info': {
...file.info,
'duration': response.durationMillis,
},
);
// .timeout(
// Durations.long4,
// onTimeout: () {
// debugPrint("timeout in getAudioGlobal");
// return null;
// },
// );
debugPrint("eventId in getAudioGlobal $eventId");
return eventId != null ? room.getEventById(eventId) : null;
} catch (err) {
debugPrint("error in getAudioGlobal");
return null;
}
'org.matrix.msc3245.voice': {},
'org.matrix.msc1767.audio': {
'duration': response.durationMillis,
'waveform': response.waveform,
},
ModelKey.transcription: {
ModelKey.text: text,
ModelKey.langCode: langCode,
},
},
);
// .timeout(
// Durations.long4,
// 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) {

Loading…
Cancel
Save