Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot record audio on iOS #288

Open
jt274 opened this issue Apr 18, 2024 · 7 comments
Open

Cannot record audio on iOS #288

jt274 opened this issue Apr 18, 2024 · 7 comments
Labels
in triage The issue is being triaged

Comments

@jt274
Copy link

jt274 commented Apr 18, 2024

Describe the bug
Audio does not record on iOS. Works fine on Android emulator and physical device. Microphone permissions are included in Info.plist.

Plugin version is 1.0.5.

Audio appears to record, but:

  • No waveforms are shown in AudioWaveforms widget during recording
  • Recorded file size is always the same
  • Waveforms are all near 0.0
  • No error during recording and a path is returned after recording using final path = await controller.stop(), but file will not play

Recording code:

await controller
            .record(
          path: '$tempDir/myfile.opus',
          sampleRate: 48000,
          bitRate: 10000,
          androidEncoder: AndroidEncoder.opus,
          iosEncoder: IosEncoder.kAudioFormatOpus,
        );

After recording a file, the path is returned and the file size of the returned file path is always 16384 bytes. Recording with the path parameter empty does not change anything.

When attempting to play back a file from the returned path after recording using the AudioFileWaveforms widget:

flutter: PlatformException(AudioWaveforms, Couldn't read into buffer. Error Domain=com.apple.coreaudio.avfaudio Code=-50 "(null)" UserInfo={false condition=buffer.frameCapacity != 0}, null, null)
flutter:
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
<asynchronous suspension>
#2      AudioWaveformsInterface.extractWaveformData (package:audio_waveforms/src/base/audio_waveforms_interface.dart:182:9)
<asynchronous suspension>
#3      PlayerController.extractWaveformData (package:audio_waveforms/src/controllers/player_controller.dart:169:20)
<asynchronous suspension>
flutter: ----------------------------------------------------

Expected behavior

  • Audio waveforms should show while recording on both platforms
  • File should record properly
  • If file cannot record properly, error should be thrown

Smartphone (please complete the following information):

  • Device: iPhone 11 physical device
  • OS: iOS 17.4.1
@Ujas-Majithiya
Copy link
Collaborator

Ujas-Majithiya commented Apr 19, 2024

@jt274 Based of this stack answer can you please lowering the bitrate?

@jt274
Copy link
Author

jt274 commented Apr 19, 2024

@Ujas-Majithiya Oh, the sample rate? If I change the sample rate to 24000 or 16000, I get No such file or directory when trying to access the file path returned by controller.stop() (and no waveforms are shown while recording). If I set the sample rate to 44100 or 48000, I get the original error posted above.

I should also note that changing the recording format to something else, such as kAudioFormatMPEG4AAC produces the same error as above.

@Ujas-Majithiya
Copy link
Collaborator

@jt274 To record with the opus encoder, your file format(extension) has to be .caf as Apple only supports their proprietary format for opus. After doing this, waves were produced, and I was able to play the audio fine after it.

But one thing to note here is that while trying to extract waves from the .caf file it was only able to read half of the file's buffer and then it threw an exception. So in UI, you will see out of 100 there are only 50 waves and the other are 0 height waves.

@jt274
Copy link
Author

jt274 commented Apr 20, 2024

@Ujas-Majithiya Unfortunately changing the file extension to .caf does not fix the issue. As I mentioned previously, the issue still occurs even if the recording format is set to AAC and the file extension to .m4a.

@Ujas-Majithiya
Copy link
Collaborator

If you are using AAC with m4a then the issue is with the bitrate. Please check if the encoder supports the bitrate you are setting. Try some higher value like 320k or make it null, recorder will take the default value.

@Ujas-Majithiya Ujas-Majithiya added the in triage The issue is being triaged label Apr 21, 2024
@jt274
Copy link
Author

jt274 commented Apr 21, 2024

@Ujas-Majithiya Ok, an update:

  • If I do not include the bitRate at all, the audio records and waveforms show. I can record in opus or aac (even typed the wrong file extension on accident and it worked). On playback, the waveforms show and sound works but I still get the Couldn't read into buffer error for some reason.

So it seems that manually setting bitRate on iOS for multiple formats does not work.

@carman247
Copy link

@jt274 thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in triage The issue is being triaged
Projects
None yet
Development

No branches or pull requests

3 participants