llfbandit / record

Audio recorder from microphone to a given file path. No external dependencies, MediaRecorder is used for Android an AVAudioRecorder for iOS.
https://pub.dev/packages/record
213 stars 174 forks source link

Takes time for recorder to start on web #321

Open sit-mraasith opened 1 month ago

sit-mraasith commented 1 month ago

This is my first time raising an issue on github.

Package version record: 5.1.0 record_web: 1.1.0

Environment

When I click on the button to record, It takes about 1-2 seconds for it to start. Is this the intended behavior or is there something that i'm doing wrong.

I have a record button that calls start. Future<void> startRecording() async { try { if (await widget._recorder.hasPermission()) { await widget._recorder.start( const RecordConfig(encoder: AudioEncoder.opus), path: '', ); setState(() { _isRecording = true; }); } } catch (e) { if (kDebugMode) { print('cannot record'); } } } the set state sets the button color when _isrecording is true and also sets the function to stoprecording.

this is my stop record function `` Future stopRecording() async { try {

final path = await widget._recorder.stop();

_audioPath = path!;

setState(() {
  _isRecording = false;
});

} catch (e) { if (kDebugMode) { print('cannot stop'); print(e); } } } `` this is my button code ( i am not using elevated button as it caused some problems without my app layout.)

GestureDetector( onTap: () { if (!_isRecording) { startRecording(); } else { stopRecording(); } }, child: Container( margin: const EdgeInsets.all(12), decoration: const BoxDecoration( image: DecorationImage( image: AssetImage(recordIcon), ), ), ), ),

Add your record configuration RecordConfig(encoder: AudioEncoder.opus)

To Reproduce

Steps to reproduce the behavior:

  1. Click on record button
  2. recorder takes 1-2 secs to start

Expected behavior it should have a faster response time so that the app feels responsive. If 1-2sec is the best that can be achieved. I will find a UI method to let the user know that they have to wait.

llfbandit commented 1 month ago

So welcome! Just stay focus and concise on the subject you want to be resolved or implemented.

Unfortunatly, I don't reproduce the same lag on my machine (either Edge or Firefox). It would be good to know if you experience this in release mode?

sit-mraasith commented 1 month ago

So welcome! Just stay focus and concise on the subject you want to be resolved or implemented.

Unfortunatly, I don't reproduce the same lag on my machine (either Edge or Firefox). It would be good to know if you experience this in release mode?

Yup, I experience this in release, I have tried it on both Chrome and Edge. Upon clicking the button it takes about 1-2 seconds before the recorder is active. This also occurs when trying to stop the recorder.

llfbandit commented 1 week ago

Are you still experiencing this issue with latest record_web 1.1.1?

Eduardo-Mateus-Da-Costa commented 2 days ago

In my case the start method does not work on the web because it needs a file and the web does not support this, on the web I used the startStream method receiving pcm16bits and converting to wav with the pcmtowav library

llfbandit commented 2 days ago

@Eduardo-Mateus-Da-Costa you can use start method on Web platform, just leave path empty. The blob Url has to be retrieved from stop method. By the way, there's no relation with the current subject.

sit-mraasith commented 2 days ago

Are you still experiencing this issue with latest record_web 1.1.1?

Yes, it still takes about 1-2 sec to start. I added an animation to my app that waits for the recorder to start. image image image

so to go from the first to the last image. i takes about 1-2 seconds. stopping the recording also takes about 1-2 seconds. the recorded audio also seems to start a bit later. like the start of my speech and the end tends to be cut off. My project involves automatic speech recognition so having parts cut out is a big problem. I am still finding ways around the problem.

llfbandit commented 1 day ago

You should rely on state stream to properly forward recorder status to UI. Also, OP states that you record to a file, now you talk about speech recognition... This issue is unclear. Maybe off topic, why don't you use stream in that case?

Are you experiencing the same with example project?

sit-mraasith commented 1 day ago

You should rely on state stream to properly forward recorder status to UI. Also, OP states that you record to a file, now you talk about speech recognition... This issue is unclear. Maybe off topic, why don't you use stream in that case?

Are you experiencing the same with example project?

I save the audio as a file and allow the user to playback the audio, so I believe I don't need to use stream in this case? correct me if I'm wrong I'm still new to this.

I am going to try it with the example project to see if it happens.