flutter-sound-stream
flutter-sound-stream copied to clipboard
Cross Platform Audio stream not playing
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.
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 ?
Yes, @CasperPas I am using WebSocket.
Dose cross-platform works?
I am also using socket io
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 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)
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
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 @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 😄
Sounds great. I am trying it now.
I updated the package, is it working well?
Yes, I tried from the branch. It's player for iOS to Android but not played for Android to iOS.
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.
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.
which devices (iOS and Android) are you using?
Can we connect over some calling platforms or on Google Meet or Google Hangout?
I think we can. You can contact me directly via the email on my profile. Both Hangout or Duo works. (please email me first 😄 )
I tried with the master branch. It's submitting audio over the cross devices. but found something new that
- Audio stream not playing if device is in silent/vibrate mode
- It's not starting the recorder sometime in iOS devices
- The received audio voice is very low if the device has same speaker and earpiece.
- If the Recording device mic comes near the input it gives the better output. I think it's a noise cancellation issue.
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!
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.
Thanks for your PR! I'm testing it. I'm so freaking busy these days 😅
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 😅
Are you sure it was not worked for iOS? It's worked for me. Can we connect for the same?
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.
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!!!
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 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
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
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
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