flutter-sound-stream icon indicating copy to clipboard operation
flutter-sound-stream copied to clipboard

Cross Platform Audio stream not playing

Open dhalloop7 opened this issue 4 years ago • 34 comments

I am writing code to stream audio data over a socket. It's working fine with Android to Android and iOS to iOS devices. But When I am trying to stream bytes from Android and trying to play on iOS It's not playing the received buffer. I also noticed that the chunk length received from the plugin is 7156 white from iOS its length is 16386.

dhalloop7 avatar May 18 '20 15:05 dhalloop7

I think the problem is on Android side, Uint16 (16bit PCM) is converted to Uint8 to transfer to dart side, iOS does the same thing but I used "pointer conversion" (withMemoryRebound). I think Android's algorithm should be refactored. I'll fix & test it over a socket. Are you using WebSocket, @dhalloop7 ?

CasperPas avatar May 19 '20 07:05 CasperPas

Yes, @CasperPas I am using WebSocket.

dhalloop7 avatar May 19 '20 10:05 dhalloop7

Dose cross-platform works?

RizanPSTU avatar May 22 '20 11:05 RizanPSTU

I am also using socket io

RizanPSTU avatar May 22 '20 11:05 RizanPSTU

I tried today ios to ios as well but it won't work for me. Android to Android share byte and play works good for me

dhalloop7 avatar May 22 '20 16:05 dhalloop7

@dhalloop7 could you provide the steps to reproduce the issue? I've tried multiple times with websocket and it's fine as long as it's not cross-platform (I'm working on that)

CasperPas avatar May 27 '20 16:05 CasperPas

I'm working on it and if you guys have any ideas, all contributions are really appreciated https://github.com/CasperPas/flutter-sound-stream/pull/5

CasperPas avatar May 28 '20 04:05 CasperPas

I am using socket.io for sending and receiving bytes from one device to another.

During initializing recorder and player I am using sampleRate 44100.

At the sender side when I am getting the bytes in the stream I am emitting those bytes with some additional information over the event.

_recorder.audioStream.listen((data) {
      socket.emit("eventName",data);
});

At the receiver side as soon as socket connects I am initializing the player and called method start. i.e

await _player.initialize();
await _player.start();

And when I am receiving the data bytes or chunks over the socket I am trying to play chunks as below.

 _socket.on(event, (data){
       _player.writeChunk(data);
});

I am also doing trial and error with changing the bit format (8, 16, 32) of recorder and player. You can try by doing it as well.

dhalloop7 avatar May 28 '20 08:05 dhalloop7

@dhalloop7 @RizanPSTU hey guys, try my PR again. I've just pushed a new commit to fix this. The main problem is byte's order: LITTLE_ENDIAN. https://github.com/CasperPas/flutter-sound-stream/pull/5

I'll do some extra tests and if it's ok, I'll publish a new version 😄

CasperPas avatar May 28 '20 11:05 CasperPas

Sounds great. I am trying it now.

dhalloop7 avatar May 28 '20 11:05 dhalloop7

I updated the package, is it working well?

CasperPas avatar May 29 '20 11:05 CasperPas

Yes, I tried from the branch. It's player for iOS to Android but not played for Android to iOS.

dhalloop7 avatar May 29 '20 11:05 dhalloop7

Can you try it again from master? I tested it with both my iPhone and simulator and it works fine. Did iOS receive the data from Android properly? Please help me test it with logging/debugging.

CasperPas avatar May 29 '20 14:05 CasperPas

I tried with the master branch. It plays the bytes from iOS to Android. iOS receiving the bytes from Android device properly but it's not playing any chunks. Whereas bytes from iOS received at the Android side are playing but not playing in iOS devices.

dhalloop7 avatar Jun 01 '20 08:06 dhalloop7

which devices (iOS and Android) are you using?

CasperPas avatar Jun 01 '20 08:06 CasperPas

Can we connect over some calling platforms or on Google Meet or Google Hangout?

dhalloop7 avatar Jun 01 '20 08:06 dhalloop7

I think we can. You can contact me directly via the email on my profile. Both Hangout or Duo works. (please email me first 😄 )

CasperPas avatar Jun 01 '20 09:06 CasperPas

I tried with the master branch. It's submitting audio over the cross devices. but found something new that

  1. Audio stream not playing if device is in silent/vibrate mode
  2. It's not starting the recorder sometime in iOS devices
  3. The received audio voice is very low if the device has same speaker and earpiece.
  4. If the Recording device mic comes near the input it gives the better output. I think it's a noise cancellation issue.

dhalloop7 avatar Jun 10 '20 10:06 dhalloop7

1.I think it it's iOS's policy. But I'll double-check that. 2.Please help me get more info on this, how to reproduce it. 3 & 4. I'll investigate further.

Thanks!

CasperPas avatar Jun 10 '20 11:06 CasperPas

I think if you check earpiece issue and route audio through the Speaker only it may solve 1st issue as well. Also, it's great if you provide a method to change the audio playing route i.e. Speaker or Earpiece or any connected device like Bluetooth or Earphone. 2nd issue I am facing sometimes only. Also, If I manually disable the microphone permission and again start the app it's not asking for permission again.

dhalloop7 avatar Jun 10 '20 12:06 dhalloop7

Thanks for your PR! I'm testing it. I'm so freaking busy these days 😅

CasperPas avatar Jun 24 '20 04:06 CasperPas

Tried your PR and it's not working on my Android phone but I found out how to make it works on Android anyway 😁 Trying your iOS code now. It's not working, I might be missing something. Gotta go now 😅

CasperPas avatar Jun 24 '20 08:06 CasperPas

Are you sure it was not worked for iOS? It's worked for me. Can we connect for the same?

dhalloop7 avatar Jun 24 '20 13:06 dhalloop7

No it's not. I copy-paste your code and tried on my Pixel 3 XL, with my bluetooth earbuds. I'll try again to make sure if it's really working or not.

CasperPas avatar Jun 24 '20 15:06 CasperPas

I'm making progress with iOS. It can be switched from headsets to built-in devices (both input & output at the same time). But on Android side, only output is switched, it always uses built-in mic for recording even when I change input source value. Trying harder now!!!

CasperPas avatar Jun 25 '20 17:06 CasperPas

https://github.com/CasperPas/flutter-sound-stream/pull/11 hi guys, please help me check this PR if it's good. It's still WIP but I'm so busy lately. 😅 Thanks!

CasperPas avatar Jul 08 '20 10:07 CasperPas

@CasperPas I tried it with android device by adding the line await _player.usePhoneSpeaker(false); It's giving output from the speaker of the phone and if I am using true it's giving output from the earpiece. That's working great. You can merge this PR #11

dhalloop7 avatar Jul 08 '20 11:07 dhalloop7

oh really? so true and false should be the other way around 🤣 true -> use built-in speaker & mic false -> use something else (bluetooth headsets, headphones

CasperPas avatar Jul 09 '20 09:07 CasperPas

Yes. But I observed that I need to keep my device in Ringing Mode. It's not playing audio while it's in silent mode even if keep Media Volume high. That's the issue. @CasperPas

dhalloop7 avatar Jul 09 '20 11:07 dhalloop7

Yes. But I observed that I need to keep my device in Ringing Mode. It's not playing audio while it's in silent mode even if keep Media Volume high. That's the issue. @CasperPas

This is normal on Android and that's a good think actually. You don't want to have phone mode in silent and have something making noise

FilipeOS avatar Jul 09 '20 11:07 FilipeOS