turn off try catch around getAudioGlobal so eerror bubbles up
This commit is contained in:
parent
c137d80f01
commit
38b70baeb2
1 changed files with 69 additions and 74 deletions
|
|
@ -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}');
|
||||
}
|
||||
|
||||
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,
|
||||
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,
|
||||
},
|
||||
},
|
||||
);
|
||||
// .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;
|
||||
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,
|
||||
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,
|
||||
},
|
||||
},
|
||||
);
|
||||
// .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…
Add table
Reference in a new issue