Access data stream as it is received - android

I've seen mention with the previous SDK as well as the current SDK that it is possible for Spotify songs to stream to the device at 1.5 times faster than their playback length. I am currently overriding the SPTAudioController and can access the audio frames as they are played back through it. My hope was that by overriding - (NSInteger)attemptToDeliverAudioFrames:(const void *)audioFrames ofCount:(NSInteger)frameCount streamDescription:(AudioStreamBasicDescription)audioDescription and returning the same count of frames that are passed in, I would immediately receive the next set of frames. This is not the case however, the frames are only delivered as fast as the song is playing, ie. I receive frames the entire time the song is playing.
How can the current Spotify SDK be used to access the audio data as soon as it is received from Spotify?
Note: although the method above is from the iOS SDK, I am interested in answers for both the Android and iOS versions.

I'm afraid the answer to this is that you aren't allowed to do so, our licenses only allows you to get the data at ~realtime speed.
Same goes for all our SDK's.

Related

Android notifications not playing at correct volume after VoIP call

I've implemented VoIP calling in a native Android application, and we've discovered a bug that I'm stuck on. I'm using Twilio for our VoIP calls if that helps at all.
If I place an outgoing VoIP call from our app, after the call ends if I put the app in the background and receive a notification, the volume of the notification is about half what it was before I placed the call. It's also not just notifications from my app, but other apps are affected as well. If I swipe my app away from the app history so it is no longer running in the background, then notifications go back to to playing at their correct volume.
This does not happen when I receive an incoming call, even though I've verified that the same code tears down the call Connection whether it's incoming or outgoing.
I've verified that when the notification is coming in, the device's notification volume is still turned all the way up using AudioManager's getStreamVolume(AudioManager.STREAM_NOTIFICATION) API.
Since all apps appear to be affected, not just my own I'm thinking I can safely assume it's not the code that's playing the notification sound that's the problem. I was thinking maybe something related to the VoIP call wasn't being released properly, and the OS itself is playing the tones at a lower volume because it still thinks we're in a call, but I can't find any evidence of that.
I've confirmed that my Connection object for the call is calling onDisconnect(), and destroy().
My ConnectionService is also being destroyed.
The call state at the time of the notification is not CALL_STATE_OFFHOOK according to the TelephonyManager.
Is there anything else you can think of that would cause notifications to play at a reduced volume?
We also experienced this same issue in our VOIP application, although in our case we're using webrtc directly and not Twilio Video -- so I don't know if this exactly applies to your case but maybe can help you find some clues.
In our case, we discovered we were not calling close() on all of the WebRTCPeer objects. That meant after the call ended, an AudioTrack was still active which affected the audio routing... resulting in the very quiet ring/notification sounds.
I would guess the equivalent with the Twilio Video SDK is to make sure that you unpublish and release all audio tracks (and video and data tracks) and then disconnect the Room object.
https://twilio.github.io/twilio-video-android/docs/latest/com/twilio/video/LocalParticipant.html#unpublishTrack-
https://twilio.github.io/twilio-video-android/docs/latest/com/twilio/video/LocalAudioTrack.html#release--
https://twilio.github.io/twilio-video-android/docs/latest/com/twilio/video/Room.html#disconnect--
We found some good clues examining the output of adb shell dumpsys audio -- in the bad state, we could see in the "Stream Volumes" section that the device for the ring/alarm/notification streams was stuck on "earpiece" rather than "speaker", and that there was an extra AudioTrack in the "Players" section.
Maybe this gives you some ideas to try... good luck!

Detecting pause in sound bytes from microphone in Flutter app

I came across this plugin -- https://pub.dev/packages/sound_stream -- on pub.dev while searching for a solution to listen to microphone from a flutter app (targeted for both android and iOS).
I am able to use this plugin to listen to user utterances from the microphone as well as playback audio when needed in my app. The requirements are as follows:
Listen to user utterances from the microphone,
Convert the audio byte stream received from the microphone into a base64 encoded string,
Send the audio string to a service by calling a REST API (POST),
Optionally, if the service responds back with audio (in form of a base64 encoded string), decode the audio output string, and play back the sound bytes.
All of these steps are working fine -- both on Android and iOS. However, in the MVP, I don't know how to detect a pause in user utterances (in the audio stream received from the microphone) and automatically trigger the REST API call. Currently my app requires the user to toggle the microphone button on and off in order to talk and then send their audio to the service. So, the user currently needs to tap on the microphone button (on my app) to activate the RecorderStream of the sound_stream plugin, speak and tap on the microphone button again to turn off the RecorderStream and at this point my app calls the API. It's like those walkie-talkies of the good old days!
I want to avoid this and seamlessly call the API when I detect a pause in the user speech and send the sound bytes received until then to the service. Any idea on how I might be able to achieve this?
Any tips will be highly appreciated.

Android 9 : How to get Audio in Background from Call made by phone in my app

I have heard a lot about blocking the call recording in android 9. I want to understand is it possible to get audio stream in a background service. Every time a user make a Call. If anyone can help me here what are approach to achieve this like giving notification/asking permission to user for this or building a system app or a plugin or a service. For me Audio stream are required to convert it into speech to text.
i got reference from android documentation for incallService,building a calling App and implementing real time text. I have no idea how to connect these three together to get Audio Stream in background service

Pause/Stop/Mute music at service interupts

I basically have an audio application that will be playing some music. I want to be able to pause/stop/mute the music when there is an interrupt.
These interrupts include: GPS directions, Phone Call, GPS, etc. (if there are more audio interupts, please let me know)
I already implemented the phone call interrupt, stops the music when phone call received and plays after phone call ends.
How would I do the other interrupts?
EDIT:
I noticed that Android's Play Music application does this. But I am unable to find the source code of that, not sure if that would be helpful.
Make sure you correctly ask for and release Audio Focus as described here:
http://developer.android.com/training/managing-audio/audio-focus.html
With multiple apps potentially playing audio it's important to think about how they should interact. To avoid every music app playing at the same time, Android uses audio focus to moderate audio playback—only apps that hold the audio focus should play audio.
Basically this allows the framework to handle interrupts properly as you cannot specifically code for every situation.

Background Audio for a Call in Progress - Possible?

I am writing a android app which is supposed to play back a audio file when a call is in progress coming from a specific number .. I tried many approaches.. but all went in vein
Separate Thread
Listener on Telephone service
starting a service in parallel
can any one please help me how to proceed regarding this ?
Update :
I am able to play a mp3 file on call recieve and i am able to play it load on speaker.. but how ever loud i play the calling party is not able to listen to it.... is there anyway i can push the speaker stream to call stream
From the api doc here
Note: You can play back the audio data only to the standard output
device. Currently, that is the mobile device speaker or a Bluetooth
headset. You cannot play sound files in the conversation audio during
a call.
So from this and lots of other so answers we can conclude that we can not play an audio during a call process.
But a long time ago from a personal experience with a handset I got a result where the audiotrack was playing while there was a call established and both the voices were heard at the same time. So I think this depends on handsets if it allows it then you can play.
You can try another thing experimentally. play the audio using a different route ( speakerphone or bluetooth).
Another option is to build your custom android build

Categories

Resources