Closed bowenchin closed 8 months ago
Codec is pcm16WAV. There's no log since the recorderModule is running and not null, however running on physical iOS device returns 0 db and duration. This is more observational and as of now I do not know where to pinpoint error log as it doesn't return an exception or error.
I have the same problem, duration aways 0 on IOS
We cannot do anything without more informations :
flutter pub deps | flutter_sound
startRecorder()
parametersopenAudioSession()
parametersAnd everything else you think can be useful to understand your issue.
Did you correctly requested the Recording permission before calling startRecorder()
?
It seems that several users have problems with the recorder.
I really think that the problem is that the API verbs are not called correctly, but it is hard for me tou understand without any logs. Be aware that the extension of the file (for example foo.wav) has no impact on the encoder used. The encoder must be specified in the startRecorder() parameters.
I will try to return better errors when the parameters are incorrects. A crash is not a good error 😉
I keep this issue open, but please give more informations.
Just a simple question : are you sure to have granted the Recording Permission before doing startRecorder() ?
Actually there is something not good in Flutter Sound : Flutter Sound does not return a correct error when the Recording Permission is not granted. This will be fixed soon.
Please check that you correctly grant the Recording Permission, and re-open this issue if you have still problems.
@Larpoux
I believe I have been able to reproduce this issue consistently.
Steps to reproduce:
openAudioSession(
mode: SessionMode.modeSpokenAudio,
focus: AudioFocus.requestFocus, //requestFocus may be related to the issue
category: SessionCategory.playAndRecord,
);
When using AudioFocus.requestFocusAndDuckOthers, the problem does not occur.
The logs link on the documentation is broken (https://tau.canardoux.xyz/guides_logs.html), can you tell me how to get the logs?
|-- flutter_sound_lite 7.5.3+1
| |-- flutter_sound_platform_interface 7.5.3+1
| |-- flutter_sound_web 7.5.3+1
Thank you @mhstoller for your investigations. I am going to look to that next week. I am currently rewriting asynchronous processing done by τ. This is a major change and tricky. After the changes, we will be able to do :
myPlayer.openAudioSession(); // no need to wait
myPlayer.startPlayer(...); // no need to wait anymore the end of `openAudioSession()`
Also if the app is waiting on something (for example) :
await myPlayer.pausePlayer();
and the app does for example :
await myPlayer.pausePlayer(); // another call to the same function
or worst :
myPlayer.stopPlayer();
The first call to pausePlayer
will receive an exception instead of being stuck for ever.
τ is in the middle of two asynchronous clients : the OS and the App. Managing asynchronous processing is really tough.
But I will look to your issue at the end of the week.
Any update on the status of this issue, or any workaround for the meanwhile?
Thanks!
Any update on the status of this issue, or any workaround for the meanwhile?
When you open the audio session try using a different focus parameter such as AudioFocus.requestFocusAndDuckOthers
As per your comment here, already tried but it didn't work.
Specifying SessionCategory.record along with AudioFocus.requestFocusAndDuckOthers seems to be working:
await _audioRecorder.openAudioSession(
focus: AudioFocus.requestFocusAndDuckOthers,
category: SessionCategory.record,
);
I was having a similar issue and configuring the AudioSession seems to have done the trick.
Future initRecorder() async {
final status = await Permission.microphone.request();
if (status == PermissionStatus.granted) {
recorder.setLogLevel(Level.error);
await recorder.openRecorder();
isRecorderReady = true;
}
if (status != PermissionStatus.granted) {
throw 'Microphone permission not granted';
}
final session = await AudioSession.instance;
await session.configure(AudioSessionConfiguration(
avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
avAudioSessionCategoryOptions:
AVAudioSessionCategoryOptions.allowBluetooth |
AVAudioSessionCategoryOptions.defaultToSpeaker,
avAudioSessionMode: AVAudioSessionMode.spokenAudio,
avAudioSessionRouteSharingPolicy:
AVAudioSessionRouteSharingPolicy.defaultPolicy,
avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none,
androidAudioAttributes: const AndroidAudioAttributes(
contentType: AndroidAudioContentType.speech,
flags: AndroidAudioFlags.none,
usage: AndroidAudioUsage.voiceCommunication,
),
androidAudioFocusGainType: AndroidAudioFocusGainType.gain,
androidWillPauseWhenDucked: true,
));
}
I have the same issue, this is the log:
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2022-10-26 14:29:47.707500+0700 Runner[19412:7529240] flutter: │ #0 FlutterSoundRecorder.startRecorder (package:flutter_sound/public/flutter_sound_recorder.dart:590:13)
2022-10-26 14:29:47.707571+0700 Runner[19412:7529240] flutter: │ #1 _CameraLiveScreen.startIntervalRecording (camera_live_screen.dart:1072:10)
2022-10-26 14:29:47.707648+0700 Runner[19412:7529240] flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2022-10-26 14:29:47.707716+0700 Runner[19412:7529240] flutter: │ 🐛 FS:---> startRecorder
2022-10-26 14:29:47.707794+0700 Runner[19412:7529240] flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2022-10-26 14:29:47.708816+0700 Runner[19412:7529240] flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2022-10-26 14:29:47.708905+0700 Runner[19412:7529240] flutter: │ #0 FlutterSoundRecorder._startRecorder (package:flutter_sound/public/flutter_sound_recorder.dart:614:13)
2022-10-26 14:29:47.708978+0700 Runner[19412:7529240] flutter: │ #1 FlutterSoundRecorder.startRecorder.
@Larpoux could you please help check above issue
Same issue here. logs:
[aurioc] AURemoteIO.cpp:1128 failed: -10851 (enable 1, outf< 2 ch, 0 Hz, Float32, deinterleaved> inf< 2 ch, 0 Hz, Float32, deinterleaved>)
*** Terminating app due to uncaught exception 'Invalid Audio Session state', reason: 'The Audio Session is not in a correct state to do Recording.'
*** First throw call stack:
(0x1806abd0c 0x197e9cee4 0x1806feef8 0x10adbaf6c 0x10adbbbcc 0x10adba0cc 0x102697098 0x102698458 0x126e619ac 0x126939e8c 0x18036b094 0x18036c094 0x18034d858 0x18034d4d0 0x1806670c4 0x1806245e8 0x180637240 0x1a1121988 0x182e3741c 0x182bd0b88 0x1026524c8 0x1028203d0)
libc++abi: terminating with uncaught exception of type NSException
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00000001baf0cbbc libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`:
-> 0x1baf0cbbc <+8>: b.lo 0x1baf0cbd8 ; <+36>
0x1baf0cbc0 <+12>: stp x29, x30, [sp, #-0x10]!
0x1baf0cbc4 <+16>: mov x29, sp
0x1baf0cbc8 <+20>: bl 0x1baf0860c ; cerror_nocancel
Target 0: (Runner) stopped.
Lost connection to device.
Exited
I was having a similar issue and configuring the AudioSession seems to have done the trick.
Future initRecorder() async { final status = await Permission.microphone.request(); if (status == PermissionStatus.granted) { recorder.setLogLevel(Level.error); await recorder.openRecorder(); isRecorderReady = true; } if (status != PermissionStatus.granted) { throw 'Microphone permission not granted'; } final session = await AudioSession.instance; await session.configure(AudioSessionConfiguration( avAudioSessionCategory: AVAudioSessionCategory.playAndRecord, avAudioSessionCategoryOptions: AVAudioSessionCategoryOptions.allowBluetooth | AVAudioSessionCategoryOptions.defaultToSpeaker, avAudioSessionMode: AVAudioSessionMode.spokenAudio, avAudioSessionRouteSharingPolicy: AVAudioSessionRouteSharingPolicy.defaultPolicy, avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none, androidAudioAttributes: const AndroidAudioAttributes( contentType: AndroidAudioContentType.speech, flags: AndroidAudioFlags.none, usage: AndroidAudioUsage.voiceCommunication, ), androidAudioFocusGainType: AndroidAudioFocusGainType.gain, androidWillPauseWhenDucked: true, )); }
This solution is working for me.
@Larpoux I have the same issue on iOS. flutter_sound: ^9.2.13 flutter sdk version: 3.7.10
This is the log:
2023-05-02 12:09:40.360876+0330 Runner[472:47934] flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-05-02 12:09:40.361133+0330 Runner[472:47934] flutter: │ #0 FlutterSoundRecorder.startRecorder (package:flutter_sound/public/flutter_sound_recorder.dart:590:13)
2023-05-02 12:09:40.361231+0330 Runner[472:47934] flutter: │ #1 AudioRecorderUtils.record (package:zireh/utils/audio_recorder.dart:64:22)
2023-05-02 12:09:40.361323+0330 Runner[472:47934] flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-05-02 12:09:40.361407+0330 Runner[472:47934] flutter: │ 🐛 FS:---> startRecorder
2023-05-02 12:09:40.361495+0330 Runner[472:47934] flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-05-02 12:09:40.363440+0330 Runner[472:47934] flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-05-02 12:09:40.363630+0330 Runner[472:47934] flutter: │ #0 FlutterSoundRecorder._startRecorder (package:flutter_sound/public/flutter_sound_recorder.dart:614:13)
2023-05-02 12:09:40.363734+0330 Runner[472:47934] flutter: │ #1 FlutterSoundRecorder.startRecorder.
2023-05-02 12:09:40.368091+0330 Runner[472:47934] flutter: ----------------------------------------------------
2023-05-02 12:09:52.170514+0330 Runner[472:47934] flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-05-02 12:09:52.170771+0330 Runner[472:47934] flutter: │ #0 FlutterSoundRecorder.stopRecorder (package:flutter_sound/public/flutter_sound_recorder.dart:726:13)
2023-05-02 12:09:52.170858+0330 Runner[472:47934] flutter: │ #1 AudioRecorderUtils.stopRecorder (package:zireh/utils/audio_recorder.dart:72:32)
2023-05-02 12:09:52.170933+0330 Runner[472:47934] flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-05-02 12:09:52.173290+0330 Runner[472:47934] flutter: │ 🐛 FS:---> stopRecorder
2023-05-02 12:09:52.173473+0330 Runner[472:47934] flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-05-02 12:09:52.174929+0330 Runner[472:47934] flutter: ┌────────────────────────────────────────────────────────────────
2023-05-02 12:09:52.174929+0330 Runner[472:47934] flutter: ┌───────────────────\342──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-05-02 12:09:52.174929+0330 Runner[472:47934] flutter: ┌───────────────────\342─────────────────────────────────────────────────────────────────────────────────────\342\224───────────────
2023-05-02 12:09:52.179329+0330 Runner[472:47934] flutter: │ #0 FlutterSoundRecorder._stopRecorder (package:flutter_sound/public/flutter_sound_recorder.dart:736:13)
2023-05-02 12:09:52.179442+0330 Runner[472:47934] flutter: │ #1 FlutterSoundRecorder.stopRecorder.
2023-05-02 12:09:52.186249+0330 Runner[472:47934] flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-05-02 12:09:52.186419+0330 Runner[472:47934] flutter: │ #0 FlutterSoundRecorder.stopRecorder (package:flutter_sound/public/flutter_sound_recorder.dart:731:13)
2023-05-02 12:09:52.186494+0330 Runner[472:47934] flutter: │ #1
and this is my code:
FlutterSoundRecorder? mRecorder;
static const theSource = AudioSource.microphone;
AudioRecorderUtils(this.mRecorder) {
_mPath = '${DateTimeUtils.fileNameFromCurrentTime}.m4a';
openTheRecorder().then((value) {
mRecorderIsInit = true;
});
}
bool mRecorderIsInit = false;
Codec _codec = Codec.aacMP4;
late String _mPath;
Future<void> openTheRecorder() async {
if (!kIsWeb) {
var status = await Permission.microphone.request();
if (status != PermissionStatus.granted) {
throw RecordingPermissionException('Microphone permission not granted');
}
}
await mRecorder!.openRecorder();
if (!await mRecorder!.isEncoderSupported(_codec) && kIsWeb) {
_codec = Codec.opusWebM;
_mPath = 'tau_file.webm';
if (!await mRecorder!.isEncoderSupported(_codec) && kIsWeb) {
mRecorderIsInit = true;
return;
}
}
final session = await AudioSession.instance;
await session.configure(AudioSessionConfiguration(
avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
avAudioSessionCategoryOptions:
AVAudioSessionCategoryOptions.allowBluetooth |
AVAudioSessionCategoryOptions.defaultToSpeaker,
avAudioSessionMode: AVAudioSessionMode.spokenAudio,
avAudioSessionRouteSharingPolicy:
AVAudioSessionRouteSharingPolicy.defaultPolicy,
avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none,
androidAudioAttributes: const AndroidAudioAttributes(
contentType: AndroidAudioContentType.speech,
flags: AndroidAudioFlags.none,
usage: AndroidAudioUsage.voiceCommunication,
),
androidAudioFocusGainType: AndroidAudioFocusGainType.gain,
androidWillPauseWhenDucked: true,
));
mRecorderIsInit = true;
}
Future<void> record() async {
await mRecorder!.startRecorder(
toFile: _mPath,
codec: _codec,
audioSource: theSource,
);
}
Future<String?> stopRecorder() async {
var url = await mRecorder!.stopRecorder();
return url;
}
}
Perhaps you can try to configure your audio session for recoding, after opening your recorder.
Here is an extract of the flutter sound example:
Future<void> openTheRecorder() async {
if (!kIsWeb) {
var status = await Permission.microphone.request();
if (status != PermissionStatus.granted) {
throw RecordingPermissionException('Microphone permission not granted');
}
}
await _mRecorder!.openRecorder();
if (!await _mRecorder!.isEncoderSupported(_codec) && kIsWeb) {
_codec = Codec.opusWebM;
_mPath = 'tau_file.webm';
if (!await _mRecorder!.isEncoderSupported(_codec) && kIsWeb) {
_mRecorderIsInited = true;
return;
}
}
final session = await AudioSession.instance;
await session.configure(AudioSessionConfiguration(
avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
avAudioSessionCategoryOptions:
AVAudioSessionCategoryOptions.allowBluetooth |
AVAudioSessionCategoryOptions.defaultToSpeaker,
avAudioSessionMode: AVAudioSessionMode.spokenAudio,
avAudioSessionRouteSharingPolicy:
AVAudioSessionRouteSharingPolicy.defaultPolicy,
avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none,
androidAudioAttributes: const AndroidAudioAttributes(
contentType: AndroidAudioContentType.speech,
flags: AndroidAudioFlags.none,
usage: AndroidAudioUsage.voiceCommunication,
),
androidAudioFocusGainType: AndroidAudioFocusGainType.gain,
androidWillPauseWhenDucked: true,
));
_mRecorderIsInited = true;
}
In your pubspec.yaml you must add those dependencies:
permission_handler: ^6.0.1
audio_session: ^0.1.6
@Zeinab-Kouhkan I hope my previous remarks will help
I'm also getting the same the audio session is not in a correct state to do recording
issue on iOS and have tried the above code (opening recorder, configuring audio session, then recording). It doesn't crash every time, but it's crashing occasionally for users on prod and I haven't figured out how to reproduce it locally.
audio_session: ^0.1.6+1 flutter_sound: ^9.2.13 flutter: 3.7.6 permission_handler: ^10.0.0
We also wanted to upgrade to get the PR for this issue: https://github.com/Canardoux/flutter_sound/issues/885#issue-1223265158
but have the same issue of crashes in production
Not reproducible on the simulator.
This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.
openRecorder
it work for me!
Ok. Thanks.
await _mRecorder!.openRecorder();
there is no openRecorder() function in the current version of the package,
is using audio_session package is enough?
/// You may not openAudioSession many recorders without releasing them.
///
/// `openRecorder()` and `closeRecorder()` return Futures.
/// You do not need to wait the end of the initialization before [startRecorder()].
/// [startRecorder] will automaticaly wait the end of `openRecorder()` before starting the recorder.
///
/// *Example:*
/// ```dart
/// myRecorder = await FlutterSoundRecorder().openRecorder();
///
/// ...
/// (do something with myRecorder)
/// ...
///
/// myRecorder.closeRecorder();
/// myRecorder = null;
/// ```
Future<FlutterSoundRecorder?> openRecorder() async {
…
}
Flutter Sound Version :
Released version
Version number 6.4.2+1
FULL
Result of the command "flutter pub deps | grep flutter_sound" (very important) |-- flutter_sound 6.4.2+1 | |-- flutter_sound_platform_interface 6.4.2+1 | |-- flutter_sound_web 6.4.2+1 | | |-- flutter_sound_platform_interface...
Severity
Platforms you faced the error
Logs
flutter: startRecorder flutter: duration: 0 flutter: db: 0.00015999999999999999
Describe the bug Flutter Sound Recorder started and not null and behaves as expected on iOS simulator. However, when testing on physical iOS device, the recorder subscription outputs 0 for duration and db, which means that it is not properly recording audio on the device.
To Reproduce Steps to reproduce the behavior:
Expected behavior Sound Recorder should work as normal both on simulator and physical device.