feat: Record voice message with opus/ogg if supported

krille/convert-ogg-to-aac-on-ios
Krille 7 months ago
parent 0bd61ced3f
commit 5f75f1d11a
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652

@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
import 'package:just_audio/just_audio.dart';
import 'package:matrix/matrix.dart';
import 'package:nyx_converter/nyx_converter.dart';
import 'package:opus_caf_converter_dart/opus_caf_converter_dart.dart';
import 'package:path_provider/path_provider.dart';
import 'package:fluffychat/utils/error_reporter.dart';
@ -77,27 +77,11 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
if (Platform.isIOS &&
matrixFile.mimeType.toLowerCase() == 'audio/ogg') {
Logs().v('Convert ogg audio file for iOS...');
final convertedFile = File('${file.path}.aac');
if (await convertedFile.exists()) {
file = convertedFile;
} else {
final completer = Completer<File>();
NyxConverter.convertTo(
file.path,
tempDir.path,
fileName: '${fileName}_${matrixFile.name}',
container: NyxContainer.aac,
execution: (
String? path,
NyxStatus status, {
String? errorMessage,
}) {
if (path != null) completer.complete(File(path));
if (errorMessage != null) completer.completeError(errorMessage);
},
);
file = await completer.future;
final convertedFile = File('${file.path}.caf');
if (await convertedFile.exists() == false) {
OpusCaf().convertOpusToCaf(file.path, convertedFile.path);
}
file = convertedFile;
}
}

@ -13,7 +13,6 @@ import 'package:fluffychat/utils/platform_infos.dart';
import 'events/audio_player.dart';
class RecordingDialog extends StatefulWidget {
static const String recordingFileType = 'm4a';
const RecordingDialog({
super.key,
});
@ -36,9 +35,11 @@ class RecordingDialogState extends State<RecordingDialog> {
Future<void> startRecording() async {
try {
final useOpus =
await _audioRecorder.isEncoderSupported(AudioEncoder.opus);
final tempDir = await getTemporaryDirectory();
final path = _recordedPath =
'${tempDir.path}/recording${DateTime.now().microsecondsSinceEpoch}.${RecordingDialog.recordingFileType}';
'${tempDir.path}/recording${DateTime.now().microsecondsSinceEpoch}.${useOpus ? 'ogg' : 'm4a'}';
final result = await _audioRecorder.hasPermission();
if (result != true) {
@ -46,14 +47,16 @@ class RecordingDialogState extends State<RecordingDialog> {
return;
}
await WakelockPlus.enable();
await _audioRecorder.start(
const RecordConfig(
RecordConfig(
bitRate: bitRate,
sampleRate: samplingRate,
numChannels: 1,
autoGain: true,
echoCancel: true,
noiseSuppress: true,
encoder: useOpus ? AudioEncoder.opus : AudioEncoder.aacLc,
),
path: path,
);

@ -11,7 +11,6 @@ import desktop_drop
import device_info_plus
import dynamic_color
import emoji_picker_flutter
import ffmpeg_kit_flutter_full_gpl
import file_selector_macos
import flutter_app_badger
import flutter_local_notifications
@ -43,7 +42,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
EmojiPickerFlutterPlugin.register(with: registry.registrar(forPlugin: "EmojiPickerFlutterPlugin"))
FFmpegKitFlutterPlugin.register(with: registry.registrar(forPlugin: "FFmpegKitFlutterPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
FlutterAppBadgerPlugin.register(with: registry.registrar(forPlugin: "FlutterAppBadgerPlugin"))
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))

@ -385,22 +385,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.2"
ffmpeg_kit_flutter_full_gpl:
dependency: transitive
description:
name: ffmpeg_kit_flutter_full_gpl
sha256: "4f269bcb636bfcb544e5b4d65c706a3d311839970cb42638e72406410c1b5b7b"
url: "https://pub.dev"
source: hosted
version: "6.0.3"
ffmpeg_kit_flutter_platform_interface:
dependency: transitive
description:
name: ffmpeg_kit_flutter_platform_interface
sha256: addf046ae44e190ad0101b2fde2ad909a3cd08a2a109f6106d2f7048b7abedee
url: "https://pub.dev"
source: hosted
version: "0.2.1"
file:
dependency: transitive
description:
@ -1286,14 +1270,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.2"
nyx_converter:
dependency: "direct main"
description:
name: nyx_converter
sha256: "29684f29a650119f0417f7faa736c5b8ac65e5b32dbae40412bd6c3d7a692fc7"
url: "https://pub.dev"
source: hosted
version: "0.1.1"
olm:
dependency: transitive
description:
@ -1302,6 +1278,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.3"
opus_caf_converter_dart:
dependency: "direct main"
description:
name: opus_caf_converter_dart
sha256: e08156066916f790a54df305e103d6dec4d853ec23147e6a02eda3c06f67ba1a
url: "https://pub.dev"
source: hosted
version: "1.0.1"
package_config:
dependency: transitive
description:

@ -66,7 +66,7 @@ dependencies:
linkify: ^5.0.0
matrix: ^0.31.0
native_imaging: ^0.1.1
nyx_converter: ^0.1.1
opus_caf_converter_dart: ^1.0.1
package_info_plus: ^6.0.0
pasteboard: ^0.2.0
path: ^1.9.0

Loading…
Cancel
Save