feat: Record voice message with opus/ogg if supported

pull/1262/head
Krille 7 months ago
parent 0bd61ced3f
commit a7473af40f
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:just_audio/just_audio.dart';
import 'package:matrix/matrix.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:path_provider/path_provider.dart';
import 'package:fluffychat/utils/error_reporter.dart'; import 'package:fluffychat/utils/error_reporter.dart';
@ -77,27 +77,11 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
if (Platform.isIOS && if (Platform.isIOS &&
matrixFile.mimeType.toLowerCase() == 'audio/ogg') { matrixFile.mimeType.toLowerCase() == 'audio/ogg') {
Logs().v('Convert ogg audio file for iOS...'); Logs().v('Convert ogg audio file for iOS...');
final convertedFile = File('${file.path}.aac'); final convertedFile = File('${file.path}.caf');
if (await convertedFile.exists()) { if (await convertedFile.exists() == false) {
file = convertedFile; OpusCaf().convertOpusToCaf(file.path, convertedFile.path);
} 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;
} }
file = convertedFile;
} }
} }

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

@ -12,6 +12,7 @@ permittedLicenses:
- BSD-2-Clause - BSD-2-Clause
- BSD-3-Clause - BSD-3-Clause
- EUPL-1.2 - EUPL-1.2
- LGPL-3.0
- MIT - MIT
- MPL-2.0 - MPL-2.0
- Zlib - Zlib

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

@ -385,22 +385,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.2" 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: file:
dependency: transitive dependency: transitive
description: description:
@ -1286,14 +1270,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.0.2" 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: olm:
dependency: transitive dependency: transitive
description: description:
@ -1302,6 +1278,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.0.3" 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: package_config:
dependency: transitive dependency: transitive
description: description:

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

Loading…
Cancel
Save