Canardoux / flutter_sound

Flutter plugin for sound. Audio recorder and player.
Mozilla Public License 2.0
877 stars 573 forks source link

Recorded sound comes out garbled and very low volume #79

Closed wyattbiker closed 4 years ago

wyattbiker commented 5 years ago

attached emulator log file nexus5x-api28.txt.zip

Version of flutter_sound

flutter/.pub-cache/hosted/pub.dartlang.org/flutter_sound-1.4.0/lib/

flutter doctor (

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, v1.2.1, on Mac OS X 10.13.6 17G6030, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3) Not using iOS [✓] Android Studio (version 3.3) [✓] IntelliJ IDEA Community Edition (version 2017.3.4) [✓] VS Code (version 1.33.1) [✓] Connected device (1 available)

Platforms you faced the error (IOS or Android or both?)

Android. I did not test using iOS.

Expected behavior

High volume and audible sound.

Actual behavior

Tested environment (Emulator? Real Device?)

Same issues on both.

Emulator: Nexus 5X API 28 Real Device: Moto G5 Plus

Steps to reproduce the behavior

just record and play it back

nordine0 commented 5 years ago

i have the same issue, when recording audio in Android the sound is not clear. Flutter: v1.2.1 flutter_sound: ^1.4.0

ghost commented 5 years ago

I've found that using the wideband codec improves audio quality. I haven't have much luck with the others, but check android_encoder.dart for the options available.

startRecorder(uri, androidEncoder: AndroidEncoder.AMR_WB);

sgon00 commented 5 years ago

androidEncoder: AndroidEncoder.AMR_WB can solve the audio quality problem.

BUT the volume is still too low. Do anyone have any ideas how to make the volume up?

I even tried with await flutterSound.setVolume(100.0);, it doesn't do anything. By looking the source code, the volume can not be greater than 1.0 anyway.

sgon00 commented 5 years ago

Hi @wyattbiker, if startRecorder(uri, androidEncoder: AndroidEncoder.AMR_WB); solves the garbled quality problem, can you please change the title to have only very low volume keyword? I tried 4 recorder plugins, and all of them gave me low volume results. This is just very weird and doesn't make sense to me.

hyochan commented 5 years ago

@sgon00 Followed by android docs I can't see any volume setting option before recording. Which device are you using?

sgon00 commented 5 years ago

@hyochan thank you very much for the reply. I am using Android physical device (Brand/Model: Mi 8 SE). All the native apps recording including built-in recorder and wechat app etc.. are working fine. If the recording volume can not be adjusted, can we allow to play the audio with volume greater than 1.0 as a workaround?

hyochan commented 5 years ago

@sgon00 I hope you to try this in different device too, to know the problem better. Since Mi is just a copycat of Apple I doubt that they customized themselves about the default device volume (this is what's being done is ios). We might have to invest other way then.

sgon00 commented 5 years ago

@hyochan but the thing is all other native apps can record audio in a normal (high) volume. Maybe the plugin can obtain volume permission and adjust the recording volume somehow before recording? I have some cheap android devices with me too. (brands: gionee, letv, more Mis). I will try on them now and should be able to report back within 10 minutes. Thanks a lot.

sgon00 commented 5 years ago

@hyochan hi, I did tests on Mi, gionee and letv running Lineageos, and set the media volume (all volumes) to the highest during tests.

gionee and letv running Lineageos have better results. The volumes recorded in flutter_sound compared to Mi's recording is higher, but are still somewhat lower than the built-in recorder and native voice chat apps. To compare all native apps recording volumes and flutter_sound volumes in all three android phones:

Mi native apps > letv running Lineageos native apps > gionee native apps > letv running Lineageos flutter_sound > gionee flutter_sound > Mi flutter_sound

So Mi native apps have the highest recording playback in all my tests and Mi flutter_sound have the lowest volume in all tests.

Btw, flutter_sound record and playback always has lower volume than the native apps.

Can we somehow add some effects to playback or increase the volume bigger than 1.0 (such as 5.0) to increase the result?

Thank you very much for your time and help.

hyochan commented 5 years ago

@sgon00 Thanks for further investment, I'll try to look for the solution.

sgon00 commented 5 years ago

@hyochan thank you very much for your time and help. 😀👍

wyattbiker commented 5 years ago

Download the recording locally and play it on your workstation. The recording sounds loud on workstation. Could it be the recording has low volume playback issues on mobile device?

On Sun, May 5, 2019, 6:50 AM sgon00 notifications@github.com wrote:

@hyochan https://github.com/hyochan thank you very much for your time and help. 😀👍

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dooboolab/flutter_sound/issues/79#issuecomment-489414530, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHDFLWKVNSTCCVOY7AMRLLPT23YFANCNFSM4HJZ6WMA .

hyochan commented 5 years ago

Download the recording locally and play it on your workstation. The recording sounds loud on workstation. Could it be the recording has low volume playback issues on mobile device? On Sun, May 5, 2019, 6:50 AM sgon00 @.***> wrote: @hyochan https://github.com/hyochan thank you very much for your time and help. 😀👍 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#79 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHDFLWKVNSTCCVOY7AMRLLPT23YFANCNFSM4HJZ6WMA .

Think it is possible. @sgon00 Hope you can try this.

sgon00 commented 5 years ago

@hyochan I have already tried this 4 days ago. Although vlc can play the flutter_sound recording file with a higher volume than the flutterSound.startPlayer(). But the flutter_sound's recorded audio file still has lower volume than the native app's recording file when both playing in vlc app. Thus, the reason why flutterSound.startPlayer() has low volume is because (1) flutterSound.startPlayer() has a lower volume playback effect. (2) the resulted recording file does has a lower volume. Due to these 2 reasons, it makes flutterSound.startPlayer() have even lower volume playback. So to workaround this low volume issue, there are two ways: (1) increase flutterSound.startPlayer() volume somehow (either by increasing the volume or adding some strengthen/boost sound effect) (2) increase the volume of the recorded result. Either of these two ways can workaround the problem. Thanks.

eduxsolano commented 5 years ago

I use this configuration and works fine.

flutterSound.startRecorder(null, androidEncoder: AndroidEncoder.AMR_NB, numChannels:2, bitRate:128000);

MsXam commented 5 years ago

Issue still occurs in latest version of the plugin 1.4.1.

Changing audio settings has no effect , i.e


await _sound.startRecorder(
          null,
          androidEncoder: AndroidEncoder.HE_AAC,
          sampleRate: 44000,
          numChannels: 2,
        );

or


await _sound.startRecorder(
          null,
          androidEncoder: AndroidEncoder.HE_AAC,
          sampleRate: 16000,
          numChannels: 1,
        );

or


await _sound.startRecorder(
          null,
          androidEncoder: AndroidEncoder.AMR_WB,
          sampleRate: 44000,
          numChannels: 2,
        );

Playing the actual file generated in MAC/WINDOWS (outside of the plugin) is the same, i.e its low quality, low sound, garbled.

I recorded using the iOS version of the plugin (on an iPhone) and shared the sound file generated to our android version of the app and it plays perfectly - so the issue is not with the audio player but with the way audio/sound is recored in the android version of the plugin.

Looking at the source code,

Try changing the OutputFormat to :

MediaRecorder.OutputFormat.AAC_ADTS

if (this.model.getMediaRecorder() == null) {
      this.model.setMediaRecorder(new MediaRecorder());
      this.model.getMediaRecorder().setAudioSource(MediaRecorder.AudioSource.MIC);
      this.model.getMediaRecorder().setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
      this.model.getMediaRecorder().setAudioEncoder(androidEncoder);
      this.model.getMediaRecorder().setAudioChannels(numChannels);
      this.model.getMediaRecorder().setAudioSamplingRate(sampleRate);

      this.model.getMediaRecorder().setOutputFile(path);

      // If bitrate is defined, the use it, otherwise use the OS default
      if(bitRate != null){
        this.model.getMediaRecorder().setAudioEncodingBitRate(bitRate);
      }
    }

Additionally, where you define and supply JSON properties :

try {
          JSONObject json = new JSONObject();
          json.put("current_position", String.valueOf(time));
          channel.invokeMethod("updateRecorderProgress", json.toString());
          recordHandler.postDelayed(model.getRecorderTicker(), model.subsDurationMillis);
        } catch (JSONException je) {
          Log.d(TAG, "Json Exception: " + je.toString());
        }

Also set the volume, as in :

*json.put("current_volume", maxVolume.toDouble() mediaRecorder!!.maxAmplitude / 32768 + 1)**

Potentially, maxVolume will be another arg to startRecorder

fritz-playmaker commented 5 years ago

Same here. Sound not clear at all. Thought my phone had fallen in water

hyochan commented 5 years ago

I will try to go over it this weekend. I hope someone could elavorate a bit. So the low recorded volume in android is the problem here?

sallymariehollywood commented 5 years ago

Same issue for me & this problem has been like this since the plugin was first created which sadly makes the plugin useless. The issue is only ANDROID. When you record and playback on either an emulator or a live device, the sound quality is a) Garbled (Squeaky) and crackling noise b) Very low volume. We have tried to change settings to the recorder like sample rate and number of channels but that makes little difference and really inflates the size. For this plugin to be perfect it would be super great if :

a) Can record in Android and playback without any issue in sound quality (No crackling or low volume) b) File size is kept small (Remember - most apps that use this plugin will want to stream the audio file to the cloud and so must be small) c) The file type is interchangeable with iOS , so if we record in Android - should be able to playback in iOS (AAC supports this) without loss of quality.

It would be great if we could work on the sound quality - I dont have experience in Android/Java so sadly cannot offer any PR for this.

Looking at the comment here : https://github.com/dooboolab/flutter_sound/issues/79#issuecomment-493444077

Did this make any difference ?

hyochan commented 5 years ago

@sallymariehollywood Thank you for your descriptive opinion. I could understand the problem really well and I've just spent time debugging.

I've had experienced poor sound quality when I've manually changed the output to AAC instead of default (tested in Galaxy note 10). The default value had been changed by those who want the file type interchangeable as you've described. Since, I don't want to experience the poor quality, I've just fixed type to DEFAULT instead of AAC in 1.5.1 release.

Currently, you can manually change all the values passed down to android sdk recorder. Therefore, I'm thinking we need to dig into the real issue happening in android itself.

hyochan commented 4 years ago

Please checkout 1.6.0

phanirithvij commented 4 years ago

@hyochan The volume is still very low flutter_sound: ^3.1.6

   flutterSoundRecorder
        .startRecorder(
      uri: _saveFile.path,
      codec: t_CODEC.CODEC_AAC,
      androidEncoder: AndroidEncoder.AMR_NB,
      numChannels: 2,
      bitRate: 128000,
    )
singh-karan-7 commented 2 years ago

This issue still exists. Any update on this?

EricKhoury commented 1 year ago

Same issue here.

anukools commented 1 year ago

Any update on this issue ? Recorded sound has very low volume.

alcampospalacios commented 2 weeks ago

I had the issue of audio very low: I resolved in this way: Changing AndroidAudioUsage.voiceCommunication by AndroidAudioUsage.media , // This made the trick

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.media, ), androidAudioFocusGainType: AndroidAudioFocusGainType.gain, androidWillPauseWhenDucked: true, ));