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

Cross Platform Audio stream not playing #2

Open
dhalloop7 opened this issue May 18, 2020 · 34 comments
Open

Cross Platform Audio stream not playing #2

dhalloop7 opened this issue May 18, 2020 · 34 comments

Comments

@dhalloop7
Copy link

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.

@CasperPas
Copy link
Owner

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 ?

@dhalloop7
Copy link
Author

Yes, @CasperPas I am using WebSocket.

@RizanPSTU
Copy link

Dose cross-platform works?

@RizanPSTU
Copy link

I am also using socket io

@dhalloop7
Copy link
Author

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

@CasperPas
Copy link
Owner

@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
Copy link
Owner

I'm working on it and if you guys have any ideas, all contributions are really appreciated
#5

@dhalloop7
Copy link
Author

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.

@CasperPas
Copy link
Owner

CasperPas commented May 28, 2020

@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.
#5

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

@dhalloop7
Copy link
Author

Sounds great. I am trying it now.

@CasperPas
Copy link
Owner

I updated the package, is it working well?

@dhalloop7
Copy link
Author

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

@CasperPas
Copy link
Owner

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.

@dhalloop7
Copy link
Author

dhalloop7 commented Jun 1, 2020

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.

@CasperPas
Copy link
Owner

CasperPas commented Jun 1, 2020

which devices (iOS and Android) are you using?

@dhalloop7
Copy link
Author

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

@CasperPas
Copy link
Owner

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

@dhalloop7
Copy link
Author

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.

@CasperPas
Copy link
Owner

CasperPas commented Jun 10, 2020

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!

@dhalloop7
Copy link
Author

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.

@CasperPas
Copy link
Owner

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

@CasperPas
Copy link
Owner

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 😅

@dhalloop7
Copy link
Author

dhalloop7 commented Jun 24, 2020

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

@CasperPas
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

#11
hi guys, please help me check this PR if it's good. It's still WIP but I'm so busy lately. 😅
Thanks!

@dhalloop7
Copy link
Author

@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

@CasperPas
Copy link
Owner

CasperPas commented Jul 9, 2020

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

@dhalloop7
Copy link
Author

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

@FilipeOS
Copy link

FilipeOS commented Jul 9, 2020

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

@dhalloop7
Copy link
Author

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

Yes, it's like a media application. Even if in Silent mode it's returning Audio with respective to Media Volume

@CasperPas
Copy link
Owner

@dhalloop7 can you help me try to fix it? Really appreciate it 😁 And I think we can create another issue for that.

@dhalloop7
Copy link
Author

@dhalloop7 can you help me try to fix it? Really appreciate it 😁 And I think we can create another issue for that.

@CasperPas Surely I will help you with this. I am also running busy these days. We can create another bug for this issue and close the current one as the cross-platform audio is streaming ;)

@dhalloop7
Copy link
Author

dhalloop7 commented Jul 10, 2020

@dhalloop7 can you help me try to fix it? Really appreciate it 😁 And I think we can create another issue for that.

@CasperPas raised PR #13 for if the device is silent or vibrate mode it can play streamed audio bytes. Can you please review and test it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants